DoctrineFixturesBundle: Loading Fixtures with PHP8 throws a PDO exception "There is no active transaction"
When running the command doctrine:fixtures:load all my fixtures are load, then a critical PDO exception is thrown
/srv # bin/console doctrine:fixtures:load
Careful, database "casechek_api2" will be purged. Do you want to continue? (yes/no) [no]:
> yes
> purging database
> loading App\Fixtures\Core\TaskFixtures
...
> loading App\Fixtures\Cases\VendorRequestTrayScanFixtures
[2022-01-26 15:26:20] console.CRITICAL: Error thrown while running command "{command}". Message: "{message}" {"exception":"[object] (PDOException(code: 0): There is no active transaction at /srv/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1853)","command":"doctrine:fixtures:load","message":"There is no active transaction"} []
15:26:20 CRITICAL [console] Error thrown while running command "doctrine:fixtures:load". Message: "There is no active transaction" ["exception" => PDOException { …},"command" => "doctrine:fixtures:load","message" => "There is no active transaction"]
In Connection.php line 1853:
There is no active transaction
doctrine:fixtures:load [--append] [--group GROUP] [--em EM] [--purger PURGER] [--purge-exclusions PURGE-EXCLUSIONS] [--shard SHARD] [--purge-with-truncate] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
I’ve seen this issue opened for migrations, but doctrine:migrations:migrate works fine for me. Is there an argument or configuration option we can use to disable auto-commit?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (5 by maintainers)
Here is a workaround that works for me. I created a custom purger that wraps an orginal ORMPurger. After calling the original purger it re-opens the transaction, if necessary.
It also contains a fix for the foreign key problem that we already had in older application (see comment above). The purger factory service provides a parameter to set whether to disable foreign key checks during purging. (If set, it will also enable foreign key checks after purging.) So you can set the behavior in services.yaml.
Then call the command with:
I’m still having this error using:
Update (2/19/2024): This is still a problem over a year later. Also, the fix below does not work if
use_savepointsis enabled in the doctrine config, I get the errorSAVEPOINT DOCTRINE_2 does not exist.A work-around is to start my own transaction in the load function, do my work, commit and then start a new transaction before returning from the method:
Have you read this other article I also wrote? https://www.doctrine-project.org/projects/doctrine-data-fixtures/en/latest/explanation/transactions-and-purging.html#transactions-and-purging
CREATE PROCEDUREis listed in the link I mentioned above. ಠ_ಠNice article, thanks for sharing.