-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
using env var fails in framework.translator.paths (cache) #24270
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
Comments
Yep, we're working on it :) see #23888 What's happening here is crucial; with this config you opt-in to dynamic values, fetched during runtime. Their real current value is not compiled into the container. So imagine in your case the application runs with
(or any other value really). Given that, the error starts making sense. Basically we cant assume what the real value is, this remains even with #23888. But feedback is welcome very much :) So to make this truly work config needs lax validation. |
thx @ro0NL I kinda understand why I have So I understand that in this case Symfony would not pick up if the ACTIVE_SITE var changed once the cache is built and I’m fine with this (but I guess this can be source of confusion too) my use case is that when I’m deploying my app I want to build the cache once and keep it for later, the env var is already set when composer runs for now I’m using but I’m not sure what will change with #23888, it seems to change the behavior of the container compilation, so I don’t know what to expect because the container compilation seems fine to me. here it fails on cache warmup. maybe env vars are not supposed to be used at that point, in that case an error message saying so should be added. or env vars can be used when warming up the cache and . maybe it should explicitly be declared in the config to avoid confusion: framework:
translator:
paths:
- "%this_value_can_be_saved_to_cache(%kernel.root_dir%/../src/ST/AppBundle/Resources/translations_sites/%active_site%)%" I hope I’m not completely off the mark here and that I didn’t misunderstood what is achieved by #23888 |
It only affects config validation. The trick is Config is aware of the placeholder values, so when encountering one we mock it with "might be value", to satisfy any checks by config. After that it returns the original placeholder value to be compiled as usual (thus in an extension
interesting :) My first thougt was a Also see #23901 for reference to this |
The exception message is buggy, but the behavior is no 8000 t a bug: not all config options are compatible with env vars. Some could be made, but until they are on a case by case basis, there should be an exception saying "hum sorry, not possible here." In the catch block of Compiler.php, the env placeholder should be replaced by the original "%env(ACTIVE_SITE)%" one, and then, the Yet, the reason why this does not apply is because the placeholder is not correctly tracked on failures. Then, and only then, we could dive into what @ro0NL explains. We should not ignore the original issue and jump on fixing the specific case of why the env var is not allowed here. Not all config options make sense with env vars. |
that could be a nice idea in fact. It's already possible on the DI extension side, calling |
|
I just checked something, |
@nicolas-grekas maybe |
Any news about this issue? Are there any plan to add ability of using env variables in compile time? |
The placeholder found in the exception message is a bug, which is fixed in #25163 |
There aren't any plans, never: everything is just contributions coming, each contributor having its own agenda and motivation. If this is a priority for you, it's up to you to make it happen :) |
I'd say let's close here. The paths configured here are evaluated when the cache is warmed up to allow the translator to build the catalogue of translation messages. Evaluating environment variables at that time will probably add confusion when one notices that changing the variable letter does not change anything in the translator. |
This PR was merged into the 3.3 branch. Discussion ---------- [DI] Fix tracking of env vars in exceptions | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24270, #24368 | License | MIT | Doc PR | - Fixes the bad exception message reported in the linked issue (regression introduced in v3.3.7). Best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/25163/files?w=1). Commits ------- 73f1ac5 [DI] Fix tracking of env vars in exceptions
@nicolas-grekas the error message is much better, thank you. I’m going to open another issue to discuss how to use env var at compile time |
when using an env var inside the value of a framework.translator.paths, the env var value is not resolved, and instead its placeholder is given to the translator
note: same thing happen if I use the env directly like that:
The text was updated successfully, but these errors were encountered: