PreFlush event is triggered on every flush even if already flushed #6564

Closed
opened 2026-01-22 15:35:02 +01:00 by admin · 2 comments
Owner

Originally created by @Seb33300 on GitHub (Nov 12, 2020).

Originally assigned to: @lcobucci on GitHub.

I am encountering an issue where doctrine events are triggered every time the flush method is called, even if the entity was persisted only once.

I am using doctrine 2.7.4 with Symfony 4.4.

Example:


// $entity is an entity with a PreFlush event attached

$entityManager->persist($entity);
$entityManager->flush(); // the PreFlush event is triggered on $entity
$entityManager->flush(); // the PreFlush event is triggered a second time on $entity even if $entity was not persisted a second time before.

Is it normal that the second flush trigger the event a second time?

I thought it should be triggered only if we persist the entity a second time:


// $entity is an entity with a PreFlush event attached

$entityManager->persist($entity);
$entityManager->flush(); // the PreFlush event is triggered on $entity
$entityManager->flush(); // should not trigger the event
$entityManager->persist($entity);
$entityManager->flush(); // should trigger the event a second time

Thank you

Originally created by @Seb33300 on GitHub (Nov 12, 2020). Originally assigned to: @lcobucci on GitHub. I am encountering an issue where doctrine events are triggered every time the flush method is called, even if the entity was persisted only once. I am using doctrine 2.7.4 with Symfony 4.4. Example: ``` php // $entity is an entity with a PreFlush event attached $entityManager->persist($entity); $entityManager->flush(); // the PreFlush event is triggered on $entity $entityManager->flush(); // the PreFlush event is triggered a second time on $entity even if $entity was not persisted a second time before. ``` Is it normal that the second flush trigger the event a second time? I thought it should be triggered only if we persist the entity a second time: ``` php // $entity is an entity with a PreFlush event attached $entityManager->persist($entity); $entityManager->flush(); // the PreFlush event is triggered on $entity $entityManager->flush(); // should not trigger the event $entityManager->persist($entity); $entityManager->flush(); // should trigger the event a second time ``` Thank you
admin added the Invalid label 2026-01-22 15:35:02 +01:00
admin closed this issue 2026-01-22 15:35:02 +01:00
Author
Owner

@flaushi commented on GitHub (Nov 17, 2020):

The preFlush event only has PreFlushEventArgs, which in turn do not have any entity, only the EntityManager is passed with them. So I think you mixed something up.

@flaushi commented on GitHub (Nov 17, 2020): The preFlush event only has PreFlushEventArgs, which in turn do not have any entity, only the EntityManager is passed with them. So I think you mixed something up.
Author
Owner

@lcobucci commented on GitHub (Nov 20, 2020):

Closing as invalid based on the discussion in #8343

@lcobucci commented on GitHub (Nov 20, 2020): Closing as invalid based on the discussion in #8343
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6564