Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using afterPersist for the OwningSide with an inversed one to one relationship leads to infinite loop #830

Closed
tandev opened this issue Feb 25, 2025 · 3 comments · Fixed by #832

Comments

@tandev
Copy link

tandev commented Feb 25, 2025

Im trying to reproduce a bug we have in multiple projects since one of the newer 2.3.* releases which sees the same entity being tried to be persisted twice with the same identifier in some relationship cases

While checking if i can reproduce in the tests, i managed to get an infite loop reproduced as follows.

Adding another test case to Zenstruck\Foundry\Tests\Integration\ORM\EdgeCasesRelationshipTest

    /** @test */
    #[Test]
    #[DataProvider('provideCascadeRelationshipsCombinations')]
    #[RequiresPhpunit('>=11.4')]
    public function inverse_one_to_one_with_non_nullable_inverse_side_after_persist(): void
    {
        $owningSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\OwningSide::class);
        $inverseSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\InverseSide::class);

        $owningSideFactory->afterPersist(function (OwningSide $owningSide) use ($inverseSideFactory) {$inverseSideFactory->create(['owningSide' => $owningSide]);})->create();

        $owningSideFactory::assert()->count(1);
        $inverseSideFactory::assert()->count(1);
    }

leads to

There was 1 error:

1) Zenstruck\Foundry\Tests\Integration\ORM\EdgeCasesRelationshipTest::inverse_one_to_one_with_non_nullable_inverse_side_after_persist with data set "Zenstruck\Foundry\Tests\Fixture\Entity\EdgeCases\InversedOneToOneWithNonNullableOwning\OwningSide::$inverseSide - no cascade
" (Zenstruck\Foundry\Tests\Fixture\DoctrineCascadeRelationship\DoctrineCascadeRelationshipMetadata Object (...))
Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '512' frames

note: this test might not fully reflect our entities and factories setup and there might still be another bug as mentioned at the start, ill try to continue reproduce it and make another bug report.

@nikophil
Copy link
Member

those inversed one-to-one are my nemesis 😅

@nikophil
Copy link
Member

nikophil commented Feb 25, 2025

not even related to inversed one to one 🤷 🤦

#832

@nikophil
Copy link
Member

released in v2.3.6
sorry for the annoyance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants