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

Skip to content

[DependencyInjection] Fix casting scalar env vars from null #50517

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
Jun 1, 2023

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented May 31, 2023

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? -
Tickets #50415
License MIT
Doc PR -

Using a casting env var processor on null returns null (it doesn't cast) which is not what one could expect and not what is documented. We could allow it.

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.

I'm fine fixing this on 5.4 !

@fancyweb fancyweb changed the base branch from 6.3 to 5.4 June 1, 2023 07:16
@fancyweb fancyweb modified the milestones: 6.3, 5.4 Jun 1, 2023
@fancyweb fancyweb force-pushed the di/cast-null-env-p branch from 6277c6d to dafa2c4 Compare June 1, 2023 07:16
@fancyweb fancyweb added the Bug label Jun 1, 2023
@fancyweb fancyweb force-pushed the di/cast-null-env-p branch from dafa2c4 to 4212e43 Compare June 1, 2023 07:18
@nicolas-grekas nicolas-grekas changed the title [DependencyInjection] Allow casting env var processors to cast null [DependencyInjection] Fix casting scalar env vars from null Jun 1, 2023
@fancyweb fancyweb force-pushed the di/cast-null-env-p branch from 4212e43 to c4b16e5 Compare June 1, 2023 07:48
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 091ac2b into symfony:5.4 Jun 1, 2023
@fancyweb fancyweb deleted the di/cast-null-env-p branch June 1, 2023 08:17
This was referenced Jun 26, 2023
@bendavies
Copy link
Contributor

bendavies commented Jun 27, 2023

is this a not a BC break, or introducion of a regression?
or neither because it's not what is documented?

previously a env var with a default of null:

parameters:
  env(SOME_VAR): ~

6.3.0:
'%env(SOME_VAR)%' will return null

6.3.1:
'%env(SOME_VAR)%' will return '' (empty string)

@fancyweb
Copy link
Contributor Author

fancyweb commented Jun 28, 2023

@bendavies Can you open a new issue please with a reproducer and I'll look at it, thanks.

nicolas-grekas added a commit that referenced this pull request Jul 3, 2023
…mpty string (fancyweb)

This PR was merged into the 5.4 branch.

Discussion
----------

[DependencyInjection] Fix autocasting null env values to empty string

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

This PR fixes autocasting `null` env values to `''`.
We continue to autocast all other values to string when there's no prefix.

It doesn't revert #50517, it just fixes an unintended side effect.

It doesn't fix #50815 request, it confirms the behavior: the solution for this issue would be to remove the `string:` prefix.

There's still no solution to have the "keep null as null" and "cast if not null" behavior.

Commits
-------

2c0815d [DependencyInjection] Fix autocasting null env values to empty string
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Jul 3, 2023
…mpty string (fancyweb)

This PR was merged into the 5.4 branch.

Discussion
----------

[DependencyInjection] Fix autocasting null env values to empty string

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | -
| Deprecations? | -
| Tickets       | symfony/symfony#50815 (comment)
| License       | MIT
| Doc PR        | -

This PR fixes autocasting `null` env values to `''`.
We continue to autocast all other values to string when there's no prefix.

It doesn't revert symfony/symfony#50517, it just fixes an unintended side effect.

It doesn't fix symfony/symfony#50815 request, it confirms the behavior: the solution for this issue would be to remove the `string:` prefix.

There's still no solution to have the "keep null as null" and "cast if not null" behavior.

Commits
-------

2c0815d04e [DependencyInjection] Fix autocasting null env values to empty string
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