-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Entity not managed since version 1.12.6 when using refresh #1112
Comments
I have similar issue since : #1099 So Entity are managed by different instances of a same "manager configuration". |
Confirmed. Happens with just bundle update with given reproducer. cc @alcaeus @nicolas-grekas |
I have a similar issue (probably related) with failing tests since upgrade to 2.0.6 [2019-12-20 15:49:54] app.CRITICAL: Multiple non-persisted new entities were found through the given association graph: * A new entity was found through the relationship 'XXXXX#XXXXX' that was not configured to cascade persist operations for entity: XXXXX@000000002ddd4e7200000000753238a0. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @manytoone(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'XXXXX#__toString()' to get a clue. [...] at /data/src/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php:105)"} [] Last known-good version is 2.0.2, couldn't test other version for different reasons: |
This is most likely related to the manager now being reset or cleared (depending on whether or not it is marked as lazy) on the |
The issue is not related to the manager now being reset or cleared, but the manager instance is not always the same instance. In manager injected thanks to services.yml, the manager is lazy loaded, but manager injected via factory for repository or form is not lazy loaded. So, we have two instances, some entities are loaded with the first, other with the second, and by example, if we test a form submit : entites fetched by the manager injected in the form are unknown for the manager injected in my persistance service. |
I won't be able to help here in the next few days sorry. |
For me, it's not an emergency, I rollback to 1.12.2. (I just pass a lot of times with xdebug to understand the issue this tomorow, if i can help, I come back the next year) |
Hmm, we haven’t had these proxy issues in a while. I still wouldn’t rule out a connection to the reset logic, but I won’t have the time to investigate over the next couple of weeks. |
mmm, i'm not entirely sure this is related to #1114 so I opened a new issue, but it feels pretty similar. |
should be resolved by using |
Thanks @bendavies but I already use |
There is one important finding: This break happens only when using Honestly, new behaviour seems correct to me. Users should not expect identity map is kept as is between requests. That kind of thing causes memore leaks. Perhaps you can ask in symfony/symfony for a feature to |
I encountered this bug on Doctrine 2.0.6, here is more details #1114 (comment) |
Hi @ostrolucky
are not a lazy service and directly the entity manager. But, in a same HTTP request, there are two intances of my entity manager, (one as lazy service and one not). And, when I load an entity A from a repository and inject into another entity B loaded/persisted by my service, the entity manager will not know A and the operation will fail. |
@frenchcomp Well this issue is related to #1099, your issue doesn't seem so, as there shouldn't be any kernel reset happenning there, so you might need to troubleshoot some more and create new issue. Perhaps #1114 is your problem. |
After the findings in #1114 I think both issues are definitely related, both stem from the way the LazyProxy resets the EM and the Entity Repositories are created, they end up with 2 different instances of the EM that mess it all up. |
@frenchcomp please read the thread. You issue will be fixed by my comment. #1112 (comment) |
@bendavies Sorry but it's not possible for us. We have 4 huge projects, we can not rewrite 240 repositories class and much more services. And more, this change in behavior is not in a major release, it's a BC Break. |
Hello @ostrolucky, I tried to comment
The repository extends |
I wasn't saying removing |
@ostrolucky ok thank you for the clarification. |
refresh -> find |
Thank you @ostrolucky. Before replacing every |
I think we're all reporting different issues and a wild guess is that other issues will arise, but there's no need to blame anyone On my side, |
@frenchcomp defining services using |
@stof, the issue is not with reseting, there are the issue at the first call. There are two instances of the entity manager in the Symfony Container. Yes, it's currently discouraged, but, this behavior was indicated in the old SF documentation (in 2.3). You want deprecated this, ok, so put a deprecated warning and change in the next major release. :) But the issue here, is not the reset, but there are two instance of the entity manager for a same namespace domaine. |
@frenchcomp can you confirm if downgrading to 2.0.2 fixes the problem of having two different instances for the entity manager service? |
Do you have some reference for that? AFAIK ServiceEntityRepository was built only to support autowiring.
There is no need to confirm such thing, you can see in #1118 that service reset is indeed causing this issue and there was no service reset being done till be9794b
Yes, that's why I would love to see #1118 merged and released ASAP, so we stop confusing one problem for the other. |
@frenchcomp the issue is with resetting. To support resetting (as the ORM instance does not support that itself), DoctrineBundle wraps the EntityManager in a proxy object (and resetting can then reset the proxy object to uninitialized state). When using the default ORM repository factory, the EntityManager instance is passed to them as
autowiring needed to have repositories defined as services. That's all. ServiceEntityRepository was built to support defining them as services in a working way, by ensuring that the repository holds a reference to the proxy EntityManager (while still making
To be exact, there is no reset being done by the bundle itself before this commit. |
The ServiceEntityRepository has been introduce in October 2017 , in a minor version of Doctrine Bundle, 2 year ago. We not use the version 2.0 of Doctrine Bundle but 1.12, the new behavior introduces into last patch is a BC Break on a minor version. I'm in favor to support only ServiceEntityRepository in the next major release, but this patch break will many projects currently in production with the current major release. The major of projects using Doctrine are supported by a very small team. Follow conventions is important. :) Throw a deprecated warning also. |
I outlined different approach at symfony/symfony#35216 (comment). I don't know why people came up with such complicated, unreliable mechanism instead of just clearing and resetting flag.
But we are not using default ORM repository factory, bundle ships its own. We could choose to ignore passed instance of EntityManager and use lazy loaded one instead (plus handling edge cases like multiple EMs) |
I tried to update to DoctrineBundle 2.0.2 but now I have this error when using
while DoctrineBundle is still in my bundles.php and with a
(can't upgrade to 2.0.6 because of the same issue as 1.12.6 (Entity not managed after a |
This was closed due to GitHub being too eager...reopening as we've "only" fixed the duplicate service problem. |
Hello @alcaeus, I tried to update to 2.0.7 and to remove the
The error is still here :
I don't have many options left, this issue is preventing me from upgrading to SF 4.4 (I have the "The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack"." error with DoctrineBundle 2.0.2) and I have tons of In the given reproducer, do you see something that I could change in order to solve this? |
@adrienfr It's just about priorities. This will work protected function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new class implements CompilerPassInterface {
public function process(ContainerBuilder $container)
{
$container->getDefinition('doctrine')->clearTag('kernel.reset');
}
}, PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
} We will document this compiler pass in upgrade guide so we can help people who rely on this behaviour migrating the code. We still think this is correct behaviour though and people were relying on a buggy behaviour so we are keeping it. |
Thank you very much @ostrolucky ! |
I added this patch on my Kernel and works perfectly, thanks. What should we do in order to avoid relying on this "buggy behaviour"? |
Assume doctrine doesn't keep state between requests. In case mentioned in this thread pretty much following:
|
Thanks ostrolucky, I'll keep it in mind for next refactors. |
Documented in #1134 |
@ostrolucky They've deleted the doc in 2.0.x tag: https://github.com/doctrine/DoctrineBundle/blob/1.12.x/UPGRADE-2.0.md https://github.com/doctrine/DoctrineBundle/blob/2.0.x/UPGRADE-2.0.md |
They didn't delete it, just didn't merge it there yet, as there wasn't release since then. |
Oh, that's right, sorry |
Hello,
When migrating from
1.12.2
to1.12.6
, my PHPUnit fails when I have a$em->refresh($entity)
inside a test.I have a skeleton app to reproduce the issue : https://github.com/adrienfr/sf-skeleton
Here is the error :
Here is my test :
And CreateEntityWebTestCase :
Am I missing a configuration change somewhere ?
The text was updated successfully, but these errors were encountered: