mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[PR #10900] RFC: Prevent UnitOfWork::commit() reentrance?
#12686
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?
Original Pull Request: https://github.com/doctrine/orm/pull/10900
State: closed
Merged: No
This PR prevents reentrant calls to
UnitOfWork::commit()with a clear exception message.Reentrance happens, for example, when users call
EntityManager::flush()from withinpostPersistor similar event listeners. Since #10547, it causes strange-looking, non-helpful error messages (#10869).Instead of treating this as a bug and trying to fix it, my suggestion is to fail with a clear exception message instead.
Reasons:
I assume the UoW was never designed to support reentrant
flush()calls in the first place. So, trying to make (or keep) this working might be a rabbit hole.The assumption is based on the following:
flush()reentrance – otherwise, such a test would have failed with the changes suggested here.preFlushorpostFlushexplicitly mentions thatflush()must not be called again. I don't know why this is not also stated for e. g.postPersist. But why would it be safe to callflush()duringpostPersist, in the middle of a transaction, when there are reasons against calling it inpostFlush, just before final cleanups are made?UnitOfWork::$entityChangeSetsorUnitOfWork::$originalEntityData. It's all to easy to mess up these states when we re-compute changesets mid-way through aflush()– and again, if that were anticipated, I'd assume to find any kind of test coverage.TODO