Bug #80260 [Com]: PDO::inTransaction() returns false when inside transaction

From: Date: Tue, 20 Oct 2020 10:03:48 +0000
Subject: Bug #80260 [Com]: PDO::inTransaction() returns false when inside transaction
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229781@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80260&edit=1 ID: 80260 Comment by: corey dot taylor dot fl at gmail dot com Reported by: corey dot taylor dot fl at gmail dot com Summary: PDO::inTransaction() returns false when inside transaction Status: Open Type: Bug Package: PDO MySQL PHP Version: 8.0.0RC2 Block user comment: N Private report: N New Comment: I see now that the implicit commit closes the transaction on the server so there is no valid "commit" after the DDL statement. I thought it just committed the changes and left the transaction open where a commit was expected. We haven't had to inspect the mysql transaction support recently. If the issue is entirely on the PDO side, then we can handle inTransaction() returning false (correctly) as long as beginTransaction() doesn't throw the error. Previous Comments: ------------------------------------------------------------------------ [2020-10-20 09:48:20] nikic@php.net The following pull request has been associated: Patch Name: Fix inconsistency in PDO transaction state On GitHub: https://github.com/php/php-src/pull/6355 Patch: https://github.com/php/php-src/pull/6355.patch ------------------------------------------------------------------------ [2020-10-20 08:54:55] corey dot taylor dot fl at gmail dot com If this turns out to be *entirely* due to DDL transactions - are you saying that PDO::inTransaction() won't support them? ------------------------------------------------------------------------ [2020-10-20 08:50:46] corey dot taylor dot fl at gmail dot com I spent some time trying to narrow down the scenarios as you mentioned. It's difficult when it happens in a complex test harness. Yes, the initial failure were showing up from a DDL transaction. I thought the same thing here that maybe there was a sync issue. However, the mysql instance clearly thinks the transaction is ok since it's waiting on a commit. After working on moving the DDL that fails out of the transactions and only putting inserts into the transaction, that initial failure stopped, but the same error occurs further down our test suite. It is possible there is a completely unrelated transaction with DDL in it before this failure, but so far I haven't found it. The test suite really only runs DDL in one place. We don't mix manual and PDO transactions. Everything be through beginTransaction, commit and rollback. ------------------------------------------------------------------------ [2020-10-20 08:44:02] nikic@php.net Okay, next guess: You are running a DDL query inside a transaction, which (for MySQL) will cause an automatic commit, even outside autocommit mode (https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html). That means inTransaction() reports false, but PDO still thinks its inside a transaction. Does that sound plausible? ------------------------------------------------------------------------ [2020-10-20 08:40:02] nikic@php.net Do you mix usage of PDO transaction APIs with transaction queries? Like, call PDO::beginTransaction() and then issue a manual COMMIT? PDO's internal state could go out of sync in such a case. We should probably make PDO internally use the same mechanism as PDO::inTransaction() to determine whether it is inside a transaction. However, I'm not sure this is really the case you're seeing, I suspect that is another problem here. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=80260 -- Edit this bug report at https://bugs.php.net/bug.php?id=80260&edit=1

« previous php.bugs (#229781) next »