Skip to content

[Messenger] PostgreSQL: NOTIFY won't work with decorated DBAL driver #45835

@Sajito

Description

@Sajito

Symfony version(s) affected

5.1.8 and up

Description

When using the DoctrineTransport with PostgreSQL, the queue table is created with a trigger to enable LISTEN/NOTIFY feature.
This is done by checking if the driver is an instance of AbstractPostgreSQLDriver.

if ($useNotify && $driverConnection->getDriver() instanceof AbstractPostgreSQLDriver) {
$connection = new PostgreSqlConnection($configuration, $driverConnection);
} else {
$connection = new Connection($configuration, $driverConnection);
}

This check won't work though, if the driver is decorated. This then leads to missing trigger to use the LISTEN/NOTIFY feature.

How to reproduce

I experienced this when when having sentry/sentry-symfony installed.
My sentry.yaml looks like this:

sentry:
  dsn: "%env(SENTRY_DSN)%"
  register_error_listener: false
  options:
    environment: "%env(SENTRY_ENV)%"
    # release: "%env(VERSION)%" #your app version

monolog:
  handlers:
    sentry:
      type: sentry
      level: !php/const Monolog\Logger::ERROR
      hub_id: Sentry\State\HubInterface

Possible Solution

Currently the check is done by checking the instance of the driver in the DoctrineTransportFactory.

if ($useNotify && $driverConnection->getDriver() instanceof AbstractPostgreSQLDriver) {

Instead of checking the Driver itself, we might get the platform and check if the platform is of type PostgreSQLPlatform like so:

if ($useNotify && $driverConnection->getDriver()->getDatabasePlatform() instanceof PostgreSQLPlatform) {

Is this a viable solution or do I miss something here?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions