-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Deprecated using env vars with cannotBeEmpty() #28858
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Using an env as part of a string would work isn't it? (foo: 'https://%env(BAR)%'
)
Worth a test case?
Correct. Test added. |
UPGRADE-4.2.md
Outdated
@@ -16,6 +16,7 @@ Config | |||
|
|||
* Deprecated constructing a `TreeBuilder` without passing root node information. | |||
* Deprecated `FileLoaderLoadException`, use `LoaderLoadException` instead. | |||
* Deprecated using placeholder values (e.g. environment variables) with `cannotBeEmpty()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove the word placeholder and use env var in all messages in this PR. It's interal details.
@@ -81,6 +81,17 @@ protected function validateType($value) | |||
*/ | |||
protected function finalizeValue($value) | |||
{ | |||
if (!$this->allowEmptyValue && $this->isHandlingPlaceholder()) { | |||
@trigger_error(sprintf('Using a placeholder value at path "%s" when empty values are not allowed by definition is deprecated since Symfony 4.2.', $this->getPath()), E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe: Setting path "%s" to an environment variable is deprecated since Symfony 4.2.
?
Also when the expected value is a string, should we suggest env vars can still be part of the option?
That could help make the notice a bit more actionable, which is important I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
Setting path "%s" to an environment variable is deprecated since Symfony 4.2.
Remove "cannotBeEmpty()" or include a non-empty string instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Thinking a bit more about this, I think it will prevent legitimate configs. Can we throw only when a custome config validator is also used? |
You mean From the issue, even without the validation rule, our conclusion remains right? We cant test an env placeholder to be empty yes/no during compile, so we abstain. |
Abstaining would mean not throwing unless we're sure this gonna be empty. |
only as of 5.0 and when not removing I see your point though, we're having the same discussion as in #26747 which lead to this change in the first place. Basically we changed the solution, now with an upgrade path via deprecation. That's at least valid on the technical side to me. We can debate about empty envs in practice, but we cant deny its possibility. I thought about allowing e.g. I think to solve the linked issue, #28838 alone is sufficient (it's about getting Tend to prefer the current behavior and assume envs not being empty compared to a conditional throw =/ So we could close here, the goal for 5.0 was noble though :)
ideally we'd infer empty yes/no from the prefix (e.g. |
I got it 😂 checking for custom validators would (at least) avoid ever passing an empty string (or null for that matter) to closures, which would always be unexpected. And affects less apps, sure :) Status: needs work |
I think we need to have a |
that could work yes, and basically let the config author control
how does it relate to Or would a new |
@ro0NL I would say that in 5.0, |
As explained above, I don't think this would be appropriate. It's very common to use an env var in a cannotbeempty option and have things just work. Breaking these without providing alternatives is a bad plan we should avoid IMHO. |
@nicolas-grekas there is no way to guarantee that the env variable will be non-empty at runtime. So if your code is fine with that, it means it does not actually care about forbidding the empty value. but anyway, I'm fine with having |
If the env var is always set in practice, the code never has to deal with empty value, that's why it works.
could be, but let's not hurry for it, as again complexity is high enough. Let's find a real use case first. |
I'm glad we're on the same level here, in terms of understanding and settling. I agree with @nicolas-grekas to not rush the complexity with new features. We should also investigate the other way around: assume envs will not be empty during runtime (check for that). If that's 9/10 cases, a opt-in thru env-prefix to indicate "could be empty" could also do it. |
@nicolas-grekas the first real-world use case is in DoctrineBundle. the default entity manager cannot be changed using an env variable |
And we also have many similar cases in Symfony itself, where some settings are necessary at compile time (look at SecurityBundle for instance) |
Ready. I've added comments to clarify the intend as much as possible :) hope it's clear like this. See #28896 for the other discussion. status: needs review |
I like this idea, we could even deprecate empty env vars and throw when one is defined in 5.0! |
@ro0NL could you please create a Symfony Docs issue for this? If possible, please review the existing docs to tell us if this new feature requires to change/remove anything in the current docs. And also, please tell us if we need to add something new. Thanks a lot! |
im hesitating we should tell ppl :) |
Thank you @ro0NL. |
…o0NL) This PR was squashed before being merged into the 4.3-dev branch (closes #28858). Discussion ---------- [DI] Deprecated using env vars with cannotBeEmpty() | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes-ish | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28827 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Continuation of #28838 for 4.2 Using environment variables for nodes marked `cannotBeEmpty()` is semantically not possible, we'll never know the value is empty yes/no during compile time. Neither we should assume one or another. Commits ------- 397c19e [DI] Deprecated using env vars with cannotBeEmpty()
This PR was merged into the 4.3-dev branch. Discussion ---------- Add upgrade from 4.2 to 4.3 | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Forgotten in #28858 i guess. cc @nicolas-grekas Commits ------- ce6ecaf Add upgrade from 4.2 to 4.3
…o0NL) This PR was merged into the 5.0-dev branch. Discussion ---------- [Config] Removed env var support with cannotBeEmpty() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> See #28858 Commits ------- ec27d74 [Config] Removed env var support with cannotBeEmpty()
Continuation of #28838 for 4.2
Using environment variables for nodes marked
cannotBeEmpty()
is semantically not possible, we'll never know the value is empty yes/no during compile time. Neither we should assume one or another.