I have created a user registry just as in the documentation. At some point later I wanted to add the CSRF. Since then it does not work properly anymore. I have the package installed and removed. https://symfony.com/doc/current/doctrine/registration_form.html
composer require security-csrf
composer remove security-csrf
rm -rf vendor
rm -rf var/cache/*
That did not help.
When I fill out the form and submit. If the user is saved. I do a second time, I get the error message below.
Only when I remove the cookie "PHPSESSID" in the browser, then I can send the form once again. After that is the same problem again.
PDOException:
There is already an active transaction
at vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1249
at PDO->beginTransaction()
(vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1249)
at Doctrine\DBAL\Connection->beginTransaction()
(vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:376)
at Doctrine\ORM\UnitOfWork->commit(null)
(vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:358)
at Doctrine\ORM\EntityManager->flush()
(src/Controller/RegistrationController.php:40)
at App\Controller\RegistrationController->registerAction(object(Request), object(UserPasswordEncoder))
(vendor/symfony/http-kernel/HttpKernel.php:149)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:66)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:190)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public/index.php:37)
I tried to debug that. The transaction was activated somewhere, then not again. I can not find the problem. Is anyone able to help me?
symfony/config/services.yaml
services:
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
- !service { class: PDO, factory: 'database_connection:getWrappedConnection' }
- { db_table: session, db_username: username, db_password: password }
I've had this same issue recently, and for me it was down to using PDOSessionHandler
along with sharing the Doctrine connection with getWrappedConnection
.
In your services.yaml
change your PdoSessionHandler
service definition
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
- !service { class: PDO, factory: 'database_connection:getWrappedConnection' }
- { lock_mode: 1 }`
I.e. just add the lock_mode argument in addition. That "fixed" it for me, though I'm looking in more depth as to why as it would be better to use LOCK_TRANSACTIONAL rather than LOCK_ADVISORY.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With