-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[DDC-2922] Error when new entities are reachable through multiple paths but not all of them are marked cascade-persist #1521
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3921 We use Jira to track the state of pull requests and the versions they got |
What happens if do not persist address ? |
@kimhemsoe Then the Email/User stuff is changed successfully. The issue is that Doctrine "fails too fast" when it finds a non-cascade-persist link leading to a new object. In this case there is another (valid, cascading) link from Email->User that should, logically speaking, be enough to let everything continue. In short, Doctrine sometimes errors if <100% of the references to an indirect new-object are cascade-persist. Ideally, it should only error if 0% of the references are cascade-persist. |
I've checked in a proof-of-concept fix to go with the test-case. |
…in saving all items
…bject graph has been better-explored
… flushes, but also flushes where specific entities are singled out.
@Ocramius : Does this issue/fix make sense? Would you prefer some other way to fix it? |
@guilhermeblanco Any thoughts? Alternatively, should Doctrine require that if an entity is cascaded in one relation, it must be also be configured as cascaded in all other possible relations? |
@Ocramius This is a bug, right? |
@DHager I need to take some time to read the tests and understand them |
@Ocramius If I recall correctly... In both cases the |
@Ocramius Without this fix, I think it forces people to exhaustively put cascading on everything/nothing, since otherwise a chance arrangement of changes may cause an error. |
Bump. |
Two-month bump: A coworker independently ran into the same issue. |
Aw, dang, I missed celebrating the 1-year birthday of this PR. |
@DHager so if I understood correctly, the issue is not about tracking new entities indirectly in cascade persist, but rather tracking association changes that cascade persist but done indirectly from a non-cascade persist. If this is correct, then there's a completely different approach to solve this problem... =\ |
Expanding on "different approach". If it is valid, then the problem is that we're not fully tracking association changes, and that would be a bigger issue. |
@guilhermeblanco IMO this is purely issue of how the ORM explores the graph, and it's being far too hasty to reject a new node when it finds a non-cascading edge, even if other cascading-edges exist but haven't been seen yet. To use an analogy:
Either the algorithm needs to check all the associations before disqualifying an entity (which is my fix in the PR) or else the documentation needs to be explicit that cascade-persist is something that must be set for all associations pointing to an entity, not just some of them. |
Nostalgia-bump. |
@DHager assuming that I still have any life force at the end of this day, I'll work on it. So far, the approach looks simple/solid: I rebased the branch locally and am trying to simplify the tests. |
…, variables, removing redundant if/else
…ally after a crash due to invalid new values detected on associations
…ally after a crash due to invalid new values detected on associations - tweaked test to make it fail
…i-new-non-cascaded-entities error message
… previous inconsistent states
@DHager I cleaned up and simplified the tests, reproduced the issue in isolation in a unit test and made sure the exception produces a message containing all involved entities. This is 🚢 -ed and ready for Thanks for all the patience (too much of it :-) ) |
Issue first-reported in DDC-2922.
As explained in the test-case, it seems to hinge on the "valid path" stemming a non-new object, so it's important that
CmsEmail
is flushed before the other things happen. If everything occurs together, the problem doesn't surface.Note that I've made a small but essential cascade-persist change to
CmsEmail
in order to show the problem, but this change to the fixtures may or may not be desirable in the long-run.