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

[Messenger] messenger:setup-transports: LOCK TABLE can only be used in transaction blocks #37179

Closed
dunglas opened this issue Jun 9, 2020 · 5 comments

Comments

@dunglas
Copy link
Member

dunglas commented Jun 9, 2020

Symfony version(s) affected: 5.1.0

Description

The messenger:setup-transports command doesn't work.

How to reproduce

bin/console messenger:setup-transports -vvv

Additional context

I'm using Postgres. Here is the stack trace:

bin/console  messenger:setup-transports -vvv

In AbstractPostgreSQLDriver.php line 79:
                                                                                                           
  [Doctrine\DBAL\Exception\DriverException]                                                                
  An exception occurred while executing 'LOCK TABLE messenger_messages;':                                  
                                                                                                           
  SQLSTATE[25P01]: No active sql transaction: 7 ERROR:  LOCK TABLE can only be used in transaction blocks  
                                                                                                           

Exception trace:
  at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php:79
 Doctrine\DBAL\Driver\AbstractPostgreSQLDriver->convertException() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169
 Doctrine\DBAL\DBALException::wrapException() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:149
 Doctrine\DBAL\DBALException::driverExceptionDuringQuery() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1102
 Doctrine\DBAL\Connection->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php:44
 Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer->processSql() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php:139
 Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer->updateSchema() at /srv/api/vendor/symfony/doctrine-messenger/Transport/Connection.php:251
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/PostgreSqlConnection.php:88
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/DoctrineTransport.php:101
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport->setup() at /srv/api/vendor/symfony/messenger/Command/SetupTransportsCommand.php:74
 Symfony\Component\Messenger\Command\SetupTransportsCommand->execute() at /srv/api/vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /srv/api/vendor/symfony/console/Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/api/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /srv/api/bin/console:42

In PDOConnection.php line 43:
                                                                                                           
  [Doctrine\DBAL\Driver\PDOException (25P01)]                                                              
  SQLSTATE[25P01]: No active sql transaction: 7 ERROR:  LOCK TABLE can only be used in transaction blocks  
                                                                                                           

Exception trace:
  at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
 Doctrine\DBAL\Driver\PDOConnection->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1100
 Doctrine\DBAL\Connection->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php:44
 Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer->processSql() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php:139
 Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer->updateSchema() at /srv/api/vendor/symfony/doctrine-messenger/Transport/Connection.php:251
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/PostgreSqlConnection.php:88
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/DoctrineTransport.php:101
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport->setup() at /srv/api/vendor/symfony/messenger/Command/SetupTransportsCommand.php:74
 Symfony\Component\Messenger\Command\SetupTransportsCommand->execute() at /srv/api/vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /srv/api/vendor/symfony/console/Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/api/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /srv/api/bin/console:42

In PDOConnection.php line 41:
                                                                                                           
  [PDOException (25P01)]                                                                                   
  SQLSTATE[25P01]: No active sql transaction: 7 ERROR:  LOCK TABLE can only be used in transaction blocks  
                                                                                                           

Exception trace:
  at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:41
 PDO->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:41
 Doctrine\DBAL\Driver\PDOConnection->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1100
 Doctrine\DBAL\Connection->exec() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php:44
 Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer->processSql() at /srv/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php:139
 Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer->updateSchema() at /srv/api/vendor/symfony/doctrine-messenger/Transport/Connection.php:251
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/PostgreSqlConnection.php:88
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection->setup() at /srv/api/vendor/symfony/doctrine-messenger/Transport/DoctrineTransport.php:101
 Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport->setup() at /srv/api/vendor/symfony/messenger/Command/SetupTransportsCommand.php:74
 Symfony\Component\Messenger\Command\SetupTransportsCommand->execute() at /srv/api/vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /srv/api/vendor/symfony/console/Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/api/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /srv/api/bin/console:42

messenger:setup-transports [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<transport>]

@dunglas
Copy link
Member Author

dunglas commented Jun 9, 2020

Removing schema_filter: ~^(?!messenger_messages)~ from doctrine.dbal config seems to fix the issue.

@burned42
Copy link
Contributor

burned42 commented Jun 22, 2020

I get the same error message, even after removing the schema_filter config.

I also wanted to note that when executing the command a second time, it succeeds without errors for me.

Downgrading doctrine/doctrine-bundle from 2.1 to 2.0.10 however fixes the problem for me.

@mitalcoi
Copy link

mitalcoi commented Jul 2, 2020

The same problem, on symfony 5.1
5.0 works well

@javiereguiluz
Copy link
Member

I can reproduce this error too:

  • Symfony 5.1.2
  • I didn't have schema_filter in any config file, so I didn't have to remove or update it.
  • Downgrading Doctrine Bundle from 2.1 to 2.0.10 fixed the problem.

Thanks!

@Offout
Copy link

Offout commented Aug 19, 2020

The same problem. symfony/messenger 5.1.3 as other Symfony components.
Works with doctrine/doctrine-bundle=2.0.10, does't work with doctrine/doctrine-bundle=2.1

nicolas-grekas added a commit that referenced this issue Sep 10, 2020
…ndas)

This PR was merged into the 5.1 branch.

Discussion
----------

[Messenger] Run postgres setup trigger in transaction

| Q             | A
| ------------- | ---
| Branch?       | 5.1 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #37179 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | n/a <!-- required for new features -->

This PR fix `messenger:setup-transports` command when using with ` doctrine/doctrine-bundle` version >= 2.1

Commits
-------

7ed93b4 Run postgres setup trigger in transaction
fabpot added a commit that referenced this issue Feb 1, 2021
…pot)

This PR was merged into the 5.2 branch.

Discussion
----------

[Messenger] Fix Doctrine setup when using a migration

| Q             | A
| ------------- | ---
| Branch?       | 5.2 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #39928 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | n/a

#38136 fixed running `messenger:setup-transports` (issue reported in #37179), but it breaks usage with `make:migration` (reported in #39928) as code is already executed in a transaction.

This PR fixes both use cases.

Commits
-------

42eeb44 [Messenger] Fix Doctrine setup when using a migration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants