Skip to content

DoctrineBundle config parameter "doctrine.dbal.logging" didn't work with value passed via env #38915

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

Closed
FallDi opened this issue Oct 31, 2020 · 3 comments

Comments

@FallDi
Copy link

FallDi commented Oct 31, 2020

Symfony version(s) affected: 5.1.8

Description
DoctrineBundle doctrine.dbal.logging configuration parameter couldn't be set via env parameter.

How to reproduce
symfony + doctrinebundle

# config/services.yaml
parameters:
     log_sql_queries: '%env(bool:LOG_SQL_QUERIES)%'
# .env
LOG_SQL_QUERIES=0
# config/packages/doctrine.yaml
doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        logging: '%log_sql_queries%'

Actual result: SQL queries are logged
Expected result: SQL queries are NOT logged

Possible root cause*
https://github.com/doctrine/DoctrineBundle/blob/6b1620354863f1f04fd4aa0a725e4ad1c728faac/DependencyInjection/DoctrineExtension.php#L139

if ($connection['logging']) {
    $logger = new Reference('doctrine.dbal.logger');
}

$connection['logging'] contains something like string(74) "env_53d7fe31b9ea8cf5_bool_LOG_SQL_QUERIES_d2a427ed60021c1b934ed0f420ebe859".
Maybe envVars should be resolved automatically earlier?

Additional context
Original issue reported to DoctrineBundle doctrine/DoctrineBundle#1244.

@stof
Copy link
Member

stof commented Oct 31, 2020

Maybe envVars should be resolved automatically earlier?

Env variables are precisely meant to be resolved at runtime and not during the compilation of the container. The initial requirement of designing that feature was that changing the value of the env variable does not require clearing the cache to recompile the container.
And so this indeed means that any configuration setting of a bundle which affects the way services are wired (rather than arguments passed to their constructor) cannot use env variable for the config.

@FallDi
Copy link
Author

FallDi commented Nov 1, 2020

Thanks for reply 👍 ! It's really clear now.

I just look from the side of a new symfony user:

Just little proposal to make a life of future users easier:

And so this indeed means that any configuration setting of a bundle which affects the way services are wired (rather than arguments passed to their constructor) cannot use env variable for the config.

Maybe it's possible to add something like this to documentation. Main idea is that not all parameters of bundle could be configured via Env.

@xabbuh
Copy link
Member

xabbuh commented Nov 3, 2020

@FallDi Can you please open an issue in the documentation repository if you think we can improve the docs around this a bit?

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

4 participants