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

Error "There is no active transaction" instead of Error about SQL syntax #1139

Closed
AntoineRoue opened this issue Mar 30, 2021 · 5 comments · Fixed by #1143
Closed

Error "There is no active transaction" instead of Error about SQL syntax #1139

AntoineRoue opened this issue Mar 30, 2021 · 5 comments · Fixed by #1143
Assignees

Comments

@AntoineRoue
Copy link

Bug Report

Syntax errors in SQL does not always display a syntax error message. It can display the error "There is no active transaction"

Q A
BC Break no
Version 3.1.1

Summary

When executing one migration with two DDL statements, if the second one has a syntax error, then the error displayed by the command is not a syntax error, but the error "There is no active transaction".
Note : I also tried when executing several migrations and in this case the error message showed is a syntax error message. It seems to happen only when migrating one file.

Current behavior

A syntax error can display the error "There is no active transaction"

How to reproduce

  1. Have all your migrations up to date
  2. Create a migration where you have two ALTER TABLE statements, and make any syntax error in the second statement.
  3. Run this migration

Code example :
$this->addSql('ALTER TABLE article ADD publish_at DATETIME DEFAULT NULL');
$this->addSql('ALTER TABLE article CHANGE publish_at DATETIME NOT NULL');

Expected behavior

A syntax error message should be displayed

@greg0ire
Copy link
Member

greg0ire commented Mar 31, 2021

A syntax error can display the error "There is no active transaction"

Can you please get a stack trace for this? See https://symfony.com/doc/current/contributing/code/stack_trace.html

Also, what RDBMS are you using? With what driver? What version of PHP? My money is on Mysql + PDO + PHP 8, because this looks somewhat related to #1104

@AntoineRoue
Copy link
Author

I am using MySQL 8.0.3 with PDO and PHP 8.
I'll get the stack trace this evening, in about 9 hours.

@AntoineRoue
Copy link
Author

Here is the stack trace :

at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php:1845
 PDO->rollBack() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php:1845
 Doctrine\DBAL\Connection->rollBack() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\Version\DbalExecutor.php:257
 Doctrine\Migrations\Version\DbalExecutor->migrationEnd() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\Version\DbalExecutor.php:115
 Doctrine\Migrations\Version\DbalExecutor->execute() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\DbalMigrator.php:101
 Doctrine\Migrations\DbalMigrator->executePlan() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\DbalMigrator.php:74
 Doctrine\Migrations\DbalMigrator->executeMigrations() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\DbalMigrator.php:151
 Doctrine\Migrations\DbalMigrator->migrate() at C:\prog\tests\symfonycertification\test-migration\vendor\doctrine\migrations\lib\Doctrine\Migrations\Tools\Console\Command\MigrateCommand.php:207
 Doctrine\Migrations\Tools\Console\Command\MigrateCommand->execute() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\console\Command\Command.php:256
 Symfony\Component\Console\Command\Command->run() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\console\Application.php:989
 Symfony\Component\Console\Application->doRunCommand() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\framework-bundle\Console\Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\console\Application.php:290
 Symfony\Component\Console\Application->doRun() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\framework-bundle\Console\Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at C:\prog\tests\symfonycertification\test-migration\vendor\symfony\console\Application.php:166
 Symfony\Component\Console\Application->run() at C:\prog\tests\symfonycertification\test-migration\bin\console:43

And some log :

[debug] "START TRANSACTION"

[info] ++ migrating DoctrineMigrations\Version20210330205434
[debug] ALTER TABLE article CHANGE name name VARCHAR(255) NOT NULL
[debug] ALTER TABLE article CHANGE name name VARCHAR(255) NOT NULL

[debug] ALTER TABLE article CHANGE name VARCHAR(255) NOT NULL
[debug] ALTER TABLE article CHANGE name VARCHAR(255) NOT NULL

[debug] "ROLLBACK"

[critical] Error thrown while running command "doctrine:migrations:migrate -n -vvv". Message: "There is no active transaction"

@greg0ire
Copy link
Member

greg0ire commented Apr 3, 2021

We can see in the stack trace that the error is occurring during a rollback, that's interesting! Maybe this could be fixed by doing a PR similar to #1131 , but for rollback? Cc @ostrolucky

@ostrolucky
Copy link
Member

Yeah looks like same issue

@greg0ire greg0ire self-assigned this Apr 3, 2021
greg0ire added a commit to greg0ire/migrations that referenced this issue Apr 3, 2021
Similarly to what happens when attempting to commit an already closed
connection when combining PHP 8 and pdo_mysql, an error is thrown when
attempting to rollback. We use the same solution as for commit(), that
is we check that we actually are inside a transaction when possible to do so.

Fixes doctrine#1139
@greg0ire greg0ire linked a pull request Apr 3, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants