mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Entity changes created by an onFlush subscriber are not executed during flush if no other changes were scheduled #5980
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kalifg on GitHub (Jun 4, 2018).
Bug Report
Summary
If you call
flush()when there are no changes (inserts, updates, deletes, etc) scheduled, no changes will be flushed — even if anonFlushsubscriber adds them.Current behavior
As described above, if you have an ORM with no registered changes, but you call
flushexpecting anonFlushsubscriber to create some changes, those changes will not be executed.The changes are registered with the ORM, and calling
flush()a second time will execute them.This is because of the early exit here
How to reproduce
We have an
onFlushsubscriber that scans the identity map for entities of a certain interface. It then performs updates on some of them. It's code that is used to process a file upload on a form, sending it to S3 and then adding the S3 path to the entity.If the user doesn't change anything else in the form, the new S3 info will not be updated either (unless we use
flush()twice). This code is paraphrased but I hope you get the idea.Expected behavior
I would expect one
flush()to be sufficient; after dispatching theonFlusheventUnitOfWorkcould check the change arrays again to make sure they are still empty.,@greentopsecret commented on GitHub (Jun 5, 2018):
@kalifg , did you consider to use
preFlushevent ?@kalifg commented on GitHub (Jun 5, 2018):
Thank you for taking the time to respond! That's a great idea and I think it will work for us. Any
onFlushlistener that does not depend on existing change sets should work just as well as apreFlush.I still think this issue needs to be resolved through at least some documentation of the phenomenon if nothing else. The difference in behavior between the two ORM states could be confusing.