mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Docs] Explicit transaction example with connection does not close EntityManager at rollback #7207
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 @ToshY on GitHub (Aug 5, 2023).
Bug Report
Summary
Doctrine\DBAL\ConnectionAPI) has lost the part that closes the EntityManager, therefore making it no longer "functionally equivalent" to the subsequent example usingEntityManager#transactional($func).Current behavior
Expected behavior
@mpdude commented on GitHub (Aug 9, 2023):
What about this code?
597a63a86c/lib/Doctrine/ORM/UnitOfWork.php (L477-L487)When an exception occurs inside
UnitOfWork::commit(), the EM is closed before the exception is re-thrown. Isn't that what you're looking for?@ToshY commented on GitHub (Aug 9, 2023):
@mpdude I don't think we are on the same page.
Doctrine\DBAL\Connection. Looking at theConnectionit only performs a rollback, and does not close the entitymanager unlikeEntityManager#transactional($func), making the following sentence in the documentation incorrect:19db7510a7/docs/en/reference/transactions-and-concurrency.rst (L87-L88)As it's currently not "funcionally equivalent", I propose to update the documentation to include
$em->close()in the catch block before the rollback, in order to be consistent with the behavior ofEntityManager#transactionalas mentioned in the text.@mpdude commented on GitHub (Aug 9, 2023):
Doesn't the UoW already close the entity manager when an exception is thrown from inside
UoW::commit()?@mpdude commented on GitHub (Aug 9, 2023):
What I want to say is:
From the user's perspective, you don't have to close the EntityManager, in neither of the two ways. The ORM code will make sure it will be closed.