Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets #50837 (comment)
License MIT
Doc PR no

The previous fix doesn't work when $processors comes from container.env_var_processors_locator.

$prefix = '';
}
$processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this);
if (false === $i && EnvVarProcessor::class === \get_class($processor)) {
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 🤔

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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 :)

Copy link
Contributor Author

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 😄

@fancyweb
Copy link
Contributor Author

Ping @bendavies can you try this patch plz?

@OskarStark OskarStark changed the title [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator Aug 2, 2023
@fancyweb fancyweb force-pushed the di/fix-null-autocast-again branch 3 times, most recently from db34fb0 to a5abf0d Compare August 4, 2023 15:30
@nicolas-grekas nicolas-grekas force-pushed the di/fix-null-autocast-again branch 2 times, most recently from 0773b18 to 38bc998 Compare August 14, 2023 13:42
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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)) {
Copy link
Member

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.

@bendavies
Copy link
Contributor

Friendly ping @bendavies can you please try this patch and report back?

@nicolas-grekas i'm afraid i'm afk on holiday for 3 weeks. i can check when i'm back if you can wait.

@bendavies
Copy link
Contributor

yes, this seems to resolve the issue.

@fancyweb fancyweb force-pushed the di/fix-null-autocast-again branch from 38bc998 to 5f0a0e2 Compare September 19, 2023 16:19
@fancyweb fancyweb force-pushed the di/fix-null-autocast-again branch from 5f0a0e2 to 766bc6e Compare September 20, 2023 06:24
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit b9c30fb into symfony:5.4 Sep 20, 2023
@fancyweb fancyweb deleted the di/fix-null-autocast-again branch September 20, 2023 11:47
This was referenced Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants