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

Open
opened 2026-01-22 15:52:07 +01:00 by admin · 0 comments
Owner

Originally created by @alexander-schranz on GitHub (Feb 6, 2025).

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

Originally created by @alexander-schranz on GitHub (Feb 6, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | 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](https://github.com/user-attachments/assets/bc5526a2-f1d9-4d56-a242-4cf6d79b593a) #### 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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7474