#11827·orm

Collection clear UnitOfWork calls DELETE query again on event listener in postFlush and so loses relations

Author: alexander-schranzCreated Feb 6, 2025Updated Aug 18, 2026

Bug Report

Q A
Version 2.17.2, 2.20.2 (tested versions)
Previous Version if the bug is a regression -

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 DELETE query is trigger again.

Image

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:

  • Controller
  • which calls a sync Message via symfony messenger
  • a MessageHandler which does load the entity do the changes and use a custom eventCollector service to add events which dispatcher after entity was saved
  • a Middleware which does the flush
  • a postFLush listener which dispatched the collected events
  • a EventListener which may edit / update other entities and call so flush again

I did avoid this complexity and put the parts into the TestConroller