Flushing multiple times triggers newEntityFoundThroughRelationship #6838

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

Originally created by @Herz3h on GitHub (Oct 1, 2021).

I'm having a weird issues where this sample code throws: A new entity was found through the relationship OutlookEventMaster#events error type

Relation is as follows:

$outlookEvent <- ManyToOne -> $outlookEventMaster

Code:

$this->em->remove($outlookEvent);
$unitOfWork = $this->em->getUnitOfWork();
dump($unitOfWork->getScheduledCollectionDeletions(), $unitOfWork->getScheduledCollectionUpdates(), $unitOfWork->getScheduledEntityDeletions(), $unitOfWork->getScheduledEntityInsertions(), $unitOfWork->getScheduledEntityUpdates());
$this->em->flush(); // This works fine

dump($unitOfWork->getScheduledCollectionDeletions(), $unitOfWork->getScheduledCollectionUpdates(), $unitOfWork->getScheduledEntityDeletions(), $unitOfWork->getScheduledEntityInsertions(), $unitOfWork->getScheduledEntityUpdates());
$this->em->flush(); // Throws the above error (this is exactly how code looks, although useless to flush twice, the reason is I need to flush something else on a following method, but that did throw the error above, so I made it simpler by just calling flush without persisting/removing anything here)

The first dumps has getScheduledEntityDeletions returning entities scheduled for deletion.

Strangely, the second dump returns empty arrays for all the scheduled things.

My lib versions:

doctrine/annotations                     1.13.2    
doctrine/cache                           2.1.1     
doctrine/collections                     1.6.8     
doctrine/common                          3.1.2     
doctrine/data-fixtures                   1.5.0     
doctrine/dbal                            2.13.3    
doctrine/deprecations                    v0.5.3    
doctrine/doctrine-bundle                 2.4.2     
doctrine/doctrine-fixtures-bundle        3.4.0     
doctrine/doctrine-migrations-bundle      2.2.2     
doctrine/event-manager                   1.1.1     
doctrine/inflector                       2.0.3     
doctrine/instantiator                    1.4.0     
doctrine/lexer                           1.2.1     
doctrine/migrations                      2.3.4     
doctrine/orm                             2.9.5     
doctrine/persistence                     2.2.2     
doctrine/sql-formatter                   1.1.1 

I have no clue why it is trying to persist an $outlookEvent related entity on the second flush.

Both sides have cascade={"remove"}

Does anyone have advice for this ? It looks like a bug, but I'm not sure

Originally created by @Herz3h on GitHub (Oct 1, 2021). I'm having a weird issues where this sample code throws: `A new entity was found through the relationship OutlookEventMaster#events` error type Relation is as follows: `$outlookEvent <- ManyToOne -> $outlookEventMaster` Code: ```php $this->em->remove($outlookEvent); $unitOfWork = $this->em->getUnitOfWork(); dump($unitOfWork->getScheduledCollectionDeletions(), $unitOfWork->getScheduledCollectionUpdates(), $unitOfWork->getScheduledEntityDeletions(), $unitOfWork->getScheduledEntityInsertions(), $unitOfWork->getScheduledEntityUpdates()); $this->em->flush(); // This works fine dump($unitOfWork->getScheduledCollectionDeletions(), $unitOfWork->getScheduledCollectionUpdates(), $unitOfWork->getScheduledEntityDeletions(), $unitOfWork->getScheduledEntityInsertions(), $unitOfWork->getScheduledEntityUpdates()); $this->em->flush(); // Throws the above error (this is exactly how code looks, although useless to flush twice, the reason is I need to flush something else on a following method, but that did throw the error above, so I made it simpler by just calling flush without persisting/removing anything here) ``` The first dumps has getScheduledEntityDeletions returning entities scheduled for deletion. Strangely, the second dump returns empty arrays for all the scheduled things. My lib versions: ``` doctrine/annotations 1.13.2 doctrine/cache 2.1.1 doctrine/collections 1.6.8 doctrine/common 3.1.2 doctrine/data-fixtures 1.5.0 doctrine/dbal 2.13.3 doctrine/deprecations v0.5.3 doctrine/doctrine-bundle 2.4.2 doctrine/doctrine-fixtures-bundle 3.4.0 doctrine/doctrine-migrations-bundle 2.2.2 doctrine/event-manager 1.1.1 doctrine/inflector 2.0.3 doctrine/instantiator 1.4.0 doctrine/lexer 1.2.1 doctrine/migrations 2.3.4 doctrine/orm 2.9.5 doctrine/persistence 2.2.2 doctrine/sql-formatter 1.1.1 ``` I have no clue why it is trying to persist an `$outlookEvent` related entity on the second flush. Both sides have `cascade={"remove"}` Does anyone have advice for this ? It looks like a bug, but I'm not sure
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6838