DDC-3101: Calling computeChangeSet twice generates invalid changeSet #3877

doctrinebot opened this Issue Apr 28, 2014 · 2 comments

2 participants


Jira issue originally created by user hosiplan:

Let's say I have an entity Answer and Question, the Question has two relations lastPost and solution. I also have a listener on preFlush for the Answer entity.

When the entity is changed (or created), the listener is called and it finds lastPost and fills the relation in Question. The change was never persisted, so I've added $UoW->computeChangeSet() at the end of the listener over the changed Question instance. The documentation mentions it at onFlush event http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preflush, but I figured it's probably the only way.

So there we go, I have working form that I submit and the relation lastPost is always updated and propagated to database as expected.

Now comes the problem.

When I change the solution relation and the lastPost is updated from listener, the changeSet that was prepared is overriden and becase the computeChangeSet method overwrites the original UoW::$originalEntityData, the new computed changeSet is wrong and contains only the new lastPost and the changes made before last call to computeChangeSet are lost (they will not be saved to database).

This is obviousely wrong and can be fixed either by not overwriting the originalEntityData property or by appending to changeSet (by fixing condition here https://github.com/doctrine/doctrine2/blob/35c8cd7f237a9a114303d14d573a28fb7d91b35e/lib/Doctrine/ORM/UnitOfWork.php#L624-L626 )

I just figured it can be solved by using onFlush and recomputeSingleEntityChangeSet, but I really like the EntityListeners and they obviousely are not called on onFlush event.


Comment created by hosiplan:

I still think this should be also doable in entity listener, but the bug appeared mostly becase of my bad usage...


Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment