mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Calling entityManager#flush in preFlush event listener causes infinite recursive loop #5791
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @egonolieux on GitHub (Nov 29, 2017).
To override the default commit order for collections because of a unique constraint (delete before insert instead of insert before delete), I manually add removed collection items to a separate array inside the entity instead of using
orphanRemoval. In apreFlushevent listener I callentityManager#removeon each removed collection item followed byentityManager#flush.However, this seems to cause the
preFlushevent to be caught in an infinite recursive loop. Although this seems somewhat expected, the documentation says it is safe to callentityManager#flushinside thepreFlushevent: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preflush, which is why I implemented it anyway.Is this a mistake in the documentation or could this be a bug?
@Ocramius commented on GitHub (Nov 29, 2017):
This is a mistake in the documentation: flushing inside lifecycle event listeners is generally NOT supported.
@egonolieux commented on GitHub (Nov 29, 2017):
Alright, that explains a lot. Could you please fix the documentation so that others won't make the same mistake?
@Ocramius commented on GitHub (Nov 29, 2017):
Please send a patch: the documentation is in this repository
On 29 Nov 2017 21:09, "Egon Olieux" notifications@github.com wrote:
Alright, that explains a lot. Could you please fix the documentation so
that others won't make the same mistake?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6857#issuecomment-347981073,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakMF8HLec1cTTdhXyhvKr6aM096Zmks5s7bn9gaJpZM4QviTA
.
@egonolieux commented on GitHub (Nov 29, 2017):
Created a pull request: https://github.com/doctrine/doctrine2/pull/6858