[PR #10485] Removing an entity that is contained in a m2m association fails when flush() is called twice #12394

Closed
opened 2026-01-22 16:13:55 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/10485

State: closed
Merged: No


Here is a failing test for #10483.

When an entity is removed that is part of a many-to-many collection, that collection will be updated during the flush() operation to no longer contain the entity.

However, afterwards the collection will be in a dirty state and the internal snapshot still contains the removed entity.

That causes the collection to be processed again when flush() is called another time. This time, the ORM assumes the entity has been removed from the collection. It will try to build a DELETE operation but fails since the entity (from the snapshot) is no longer in the identity map.

The error message is Doctrine\ORM\EntityNotFoundException: Unable to find "..." entity identifier associated with the UnitOfWork.

**Original Pull Request:** https://github.com/doctrine/orm/pull/10485 **State:** closed **Merged:** No --- Here is a failing test for #10483. When an entity is removed that is part of a many-to-many collection, that collection will be updated during the `flush()` operation to no longer contain the entity. However, afterwards the collection will be in a dirty state and the internal snapshot still contains the removed entity. That causes the collection to be processed again when `flush()` is called another time. This time, the ORM assumes the entity has been removed from the collection. It will try to build a `DELETE` operation but fails since the entity (from the snapshot) is no longer in the identity map. The error message is `Doctrine\ORM\EntityNotFoundException: Unable to find "..." entity identifier associated with the UnitOfWork`.
admin added the pull-request label 2026-01-22 16:13:55 +01:00
admin closed this issue 2026-01-22 16:13:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#12394