-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Fix autocasting null
env values to empty string with container.env_var_processors_locator
#51198
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
[DependencyInjection] Fix autocasting null
env values to empty string with container.env_var_processors_locator
#51198
Conversation
$prefix = ''; | ||
} | ||
$processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this); | ||
if (false === $i && EnvVarProcessor::class === \get_class($processor)) { |
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.
or instanceof I don't know?
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.
Why is this extra condition needed at all? I removed it and tests still pass.
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.
Because we implemented the empty string behavior only in our EnvVarProcessor class.
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.
Looking at this again, I think it's safer to add the condition 🤔
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'm not fan of hardcoding a behavior for EnvVarProcessor only. Can't we add some phpdoc in the interface to explain how a processor should behave 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.
We could, but my point is that we added this special behavior on 5.4 as a bug fix 😅 Isn't it too late to change the behavior for every consumer?
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 it's too much an edge case, nobody replaced the "string" processor :)
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 added a comment but I'm not convinced it's needed/understandable. I let you takeover 😄
Ping @bendavies can you try this patch plz? |
null
env values to empty string with container.env_var_processors_locator
db34fb0
to
a5abf0d
Compare
0773b18
to
38bc998
Compare
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.
Friendly ping @bendavies can you please try this patch and report back?
$prefix = ''; | ||
} | ||
$processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this); | ||
if (false === $i && EnvVarProcessor::class === \get_class($processor)) { |
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.
Why is this extra condition needed at all? I removed it and tests still pass.
@nicolas-grekas i'm afraid i'm afk on holiday for 3 weeks. i can check when i'm back if you can wait. |
yes, this seems to resolve the issue. |
38bc998
to
5f0a0e2
Compare
src/Symfony/Component/DependencyInjection/EnvVarProcessorInterface.php
Outdated
Show resolved
Hide resolved
… with container.env_var_processors_locator
5f0a0e2
to
766bc6e
Compare
Thank you @fancyweb. |
The previous fix doesn't work when
$processors
comes fromcontainer.env_var_processors_locator
.