-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] ManagerRegistry::resetService breaks entity manager identities #35216
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
Comments
I think the main issue here is that the entity manager once closed cannot really be reopened (since Doctrine cannot guarantee that the entity state is consistent any more). AFAIK this is the root cause that forces The problem here arises when the As long as Doctrine doesn't provide a way to cleanly reopen the existing entity manager (and basically ensuring that |
As you can see, this method is willing to break encapsulation with Closure::bind already, so I don't see why it can't just do clear() and force set the closed flag to false. Also I don't really buy reasoning that doctrine closes entity manager because it can no longer guarantee entity state -> there is no entity state when error happens, because close does clear() first. |
Apologies, I didn't realize I wonder though, is this maybe something deeper that should be addressed within Doctrine? If it's safe to reopen a closed EM after a clear, shouldn't Doctrine provide a |
Yes but that would be a new feature, while this is a bug. Bridge should first fix resetting in a way that does not break identities, doctrine itself can in future provide easier way to do it. |
Would be great to understand what are the deeper implications in the ORM (if there are some, which is implied by reading the EM code comments) of reopening an EM. I always thought it was more of a DBAL thing, being unable to reopen the actual DB connections after a failure. |
Injecting The issue happens when you define an entity repository as a service without using the ServiceEntityRepository feature. this is a known issue. and that's why DoctrineBundle and Symfony said for years that Doctrine repositories should not be defined as services (and that's why we implemented ServiceEntityRepository to have a way to define them as services). The always-working way to reopen an entity manager would require to be able to reopen the existing entity manager, which would require the ORM itself to have such feature (and I don't see that coming to a 2.x release). |
@stof afaik with a For reference, your issue in doctrine/orm#5933 |
For future reference once anyone has the same issue as I had:
When using this in a Symfony messenger setup. One of your jobs triggers an exception in the EntityManager which will close the entitymanager. You will run into very strange errors. Since on the second job your repository and entitymanager in this situation are not having the same UnitOfWork. The way to fix this is not having a property for your repository, but fetch it on access from the entitymanager which is nicely reset. |
Hey, thanks for your report! |
. |
@carsonbot This is still relevant, yep! |
Hey, thanks for your report! |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
This is still relevant dear Carson
…On Tue, 14 Sep 2021 at 15:02 Carson: The Issue Bot ***@***.***> wrote:
Friendly ping? Should this still be open? I will close if I don't hear
anything.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#35216 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGJNPKG2UGFUQNTYR5LN5LUB5BXZANCNFSM4KCZIY2Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hey, thanks for your report! |
No, I haven't found a workaround :)
…On Tue, Mar 15, 2022 at 2:03 PM Carson: The Issue Bot < ***@***.***> wrote:
Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still
relevant? Have you managed to find a workaround?
—
Reply to this email directly, view it on GitHub
<#35216 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGJNPPJ3SGL33RLTL5DRVLVACDDHANCNFSM4KCZIY2Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
The workaround is similar to what has been described before:
Of course it'd be better if we could have a working "reset" method on Doctrine's side. |
Because the way how symfony resets em breaks identities. Argument that there is no support for it in orm doesn't stand considering symfony already uses closure:: bind to break through encapsulation. |
Because then we'd be crossing a responsibility boundary, namely doing something that is within Doctrine's area. /cc @acasademont also since you were wondering about why we don't use Closure::bind to hack into Doctrine's state. Resetting this state should be done on Doctrine's side. |
Closing as explained in favor of doctrine/orm#5933 |
Yep, makes sense to fix it upstream and then get rid of the nasty proxy hack in Symfony |
…ed as ghost objects (nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [DoctrineBridge] Don't reinit managers when they are proxied as ghost objects | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Paving the way to #35345 Interface `GhostObjectInterface` extends `LazyLoadingInterface` but breaks LSP because `setProxyInitializer()` takes another kind of closure as argument. This won't solve #35216 since resetting a closed entity manager won't happen anymore if we start to use ghost object proxies. But at least this code won't explode. /cc @ostrolucky any idea what we could put inside the added "if" to solve #35216? Would you be up to submit a PR doing that, branch 6.2 I guess since that'd be a new feature? Commits ------- 1dbf3a6 [DoctrineBridge] Don't reinit managers when they are proxied as ghost objects
This method is inherently very unsafe to use, because it changes instance of wrapped entity manager, while other instances of said entity manager are untouched, which causes desynchronized identity maps.
We should think about other approach how to reopen entity manager, without breaking identitiees.
More info in doctrine/DoctrineBundle#1118 and doctrine/DoctrineBundle#1114
The text was updated successfully, but these errors were encountered: