Skip to content

[DoctrineMessenger] Unknown type error on auto setup when multiple symfony apps with different types config #49647

Closed
@maxime-aknin

Description

@maxime-aknin

Symfony version(s) affected

5.x, 6.x

Description

I stumbled upon an edge case with doctrine-messenger and the auto table setup feature. It turns out any dbal schema_filter config is discarded when auto creating the messages tables (see Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection::setup function).

But having multiple symfony applications sharing the same database, I use this config to filter out the tables doctrine should handle, depending on the application. The issue arises when you have custom dbal types in one application, but not the other. The auto setup process throws a Doctrine\Dbal\Exception::unknownColumnType, because there are unknown types in tables that are from the other app (and normally excluded by the schema filter dbal option)

How to reproduce

  1. Make a symfony app and define custom dbal type mapping, e.g.
doctrine:
  dbal:
    schema_filter: "~^app1_~"
    types:
       custom_type: Acme\Type\Custom
  1. Make another symfony app, sharing the same database, but without custom types definition
doctrine:
  dbal:
    schema_filter: "~^app2_~"
  1. Install Messenger on the second app and try to use the doctrine transport, the unknown type exception should be thrown, you'd have to create the table manually.

Possible Solution

Given that it might be difficult to only exclude the messenger table from the schema filter regex if it exist (depending on the regex), I propose to add a specific option directly in messenger transport config, to specify the schema_filter to use on auto_setup, if needed. E.g.

framework:
  messenger:
    transports:
      async:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        options: 
          auto_setup: true
          setup_dbal_schema_filter: "~^(?!app1_)~"

I already made this commit as a proposition, but I don't know if that would be the correct way to approach this issue (nor really how to add tests for it), so I prefered not opening a PR right away.

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