-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 4.4.2
symfony/messenger v4.4.2
Description
Using different config depending on environment doesn't let me override auto_setup, instead causes InvalidArgumentException with: Unknown option found : [0]. Allowed options are [messenger_messages, default, 3600, 1]
This shows two problems: There is something wrong in config parsing and the exception message is computed incorrectly.
Additional problem: options take precedence before DSN query parameters, so having auto_setup: false in the config cannot be overriden neither by config nor DSN.
How to reproduce
config/packages/messenger.yaml contains:
framework:
messenger:
transports:
doctrine:
dsn: doctrine://default
options:
auto_setup: false
routing:
'*': doctrine
config/packages/dev/messenger.yaml and/or config/packages/test/messenger.yaml contains:
framework:
messenger:
transports:
doctrine:
dsn: doctrine://default #?auto_setup=true
options:
auto_setup: true
With this config Symfony\Component\Messenger\Transport\Doctrine\Connection::buildConfiguration contains [1 => 0] in $optionsExtraKeys in L86, thus throws the exception in L88.
If I change config/test/messenger.yaml to contain the auto_setup as query in the DSN instead (without configuring the auto_setup option in any messenger.yaml) everything works, which proves that overriding the DSN in the test config works, just auto_setup does not.
The exeption incorrectly uses implode(', ', self::DEFAULT_OPTIONS)
instead of implode(', ', array_keys(self::DEFAULT_OPTIONS))
for its message, this error is duplicated in L94 when $queryExtraKeys are found.
Because buildConfiguration() uses $configuration += $options + $query + self::DEFAULT_OPTIONS;
in L81 it is not possible to override options via DSN and thus via env/env.local/ENV/...
Possible Solution
for the exception message: use implode(', ', array_keys(self::DEFAULT_OPTIONS))
for the precedence: use $configuration += $query + $options + self::DEFAULT_OPTIONS;
(switch $options & $query) to allow the DSN to override options via query, e.g. use dsn: doctrine://default?auto_setup=true
for the config parsing / extra keys: I don't know