mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Collection clear UnitOfWork calls DELETE query again on event listener in postFlush and so loses relations #7474
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 @alexander-schranz on GitHub (Feb 6, 2025).
Bug Report
Summary
Collection clear UnitOfWork calls DELETE query again on event listener in postFlush and so loses relations.
Current behavior
It seems like the postFlush event the UnitOfWork is not correctly cleaned up and the
DELETEquery is trigger again.Expected behavior
DELETE query should only triggered once and not again in additional flush.
How to reproduce
I created a reproducer repository here: https://github.com/alexander-schranz/doctrine-unit-of-work-flush-clear-reproducer
The important file is this one:
https://github.com/alexander-schranz/doctrine-unit-of-work-flush-clear-reproducer/blob/main/src/Controller/TestController.php
Normally this is kind of splitted up in several services:
ControllerMessagevia symfony messengerMessageHandlerwhich does load the entity do the changes and use a customeventCollectorservice to add events which dispatcher after entity was savedMiddlewarewhich does the flushI did avoid this complexity and put the parts into the TestConroller