mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
PHP 8: "PDOException: There is no active transaction" #7395
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 @JarJak on GitHub (Jul 3, 2024).
Bug Report
I am not sure if this is bug for ORM or DBAL.
Versions:
PHP 8.2
ORM 2.19.5
DBAL 3.8.6
Symfony 8.2
Postgres 13.7
DBAL config:
Summary
When using transactions inside code, when exception occurs "entitymanager is closed" and transaction is rollbacked, that results in "PDOException: There is no active transaction" error.
I have seen similar bugs reported, but they either happen with MySQL/MariaDB or in migrations. For me this happens with Postgres and in regular app code.
Even though before rollbacking, Doctrine checks if it has a flag for active transaction before sending
ROLLBACKsql to the database, for some reason this does not always work.Code fragment from UoW commit() method (which is always called in flush() regardless of transaction mode): https://github.com/doctrine/orm/blob/3.2.x/src/UnitOfWork.php#L439
Proposed solution
One "dirty and hacky" way to fix it would be to add another try/catch inside the code above: