Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine_Export is trying to commit when there is no active transaction on PHP 8.0 #130

Open
mcgrogan91 opened this issue Apr 3, 2024 · 1 comment

Comments

@mcgrogan91
Copy link

This appears to be an issue in PHP 8.0, with a database like MySQL/MariaDB that has implicit commits.

We're currently in the process of upgrading from PHP 7.4 to 8.0 (then to other 8.x versions, 8.0 is an intermediate update)

Our build process for our test environments involves running doctrine:build --all, which as part of its execution calls sfDoctrineInsertSqlTask. This task ends up calling \Doctrine_Export::exportClasses. This method generates a bunch of DDL commands and runs them inside a transaction, finally calling commit.

In PHP 7.4, this ran into no issues.
In PHP 8.0, we are getting a PDOException with the text "There is no active transaction".

It looks like the root cause of this is the PDO classes internal transaction state tracking becoming out of sync with the database when the database implicitly commits. In 7.4 this used to just be silent and the commit call would essentially be a no-op. In 8.0 the internal transaction state tracking of PDO was updated to begin throwing this exception when it recognized the actual connection was no longer in a transaction.

Here is a related issue with its fix in the modern doctrine/migrations library: doctrine/migrations#1104. For that issue they updated their migration-related commit calls to first check if they were still in an active transaction (and have isTransactional for a more permanent fix).

Given the behavior of exportClasses to almost always contain DDL queries, I think it likely makes sense to check if we're still in a transaction before calling commit. This behavior could also be an override of the exportClasses method in \Doctrine_Export_Mysql. Interested in hearing other thoughts on this or if there's something I missed.

@connorhu
Copy link
Collaborator

connorhu commented Apr 4, 2024

Thanks for the detailed description.
It took me a while to find, this is the PR for issue #1104: doctrine/migrations#1131
The TransactionHelper in that PR seems to me to be an reasonable fix. If the connections is PDO and we are inTransaction then commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants