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

Skip to content

[DI] Remove default env type check on validate #27470

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

Closed
wants to merge 1 commit into from
Closed

[DI] Remove default env type check on validate #27470

wants to merge 1 commit into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Jun 1, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27455
License MIT
Doc PR symfony/symfony-docs#...

The default env is already validated to be a scalar or null on get()

'scalar_node' => '%env(NULLED)%',
'int_node' => '%env(int:FOO)%',
'float_node' => '%env(float:BAR)%',
'float_node' => '%env(FLOATISH)%',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this fails, im not sure what we expect here. Env without a prefix is now assumed to be a scalar which is not allowed for float-only node.

Copy link
Member

@nicolas-grekas nicolas-grekas Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use is_numeric() somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a scalar issue in general, directly related to

if (null !== $defaultValue && !is_scalar($defaultValue)) {
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', gettype($defaultValue), $name));
}

im not sure what's the behavior we're seeking... what does "env without prefix" mean on its value? It if can be any scalar then using it for a float node is invalid, technically.

to make it work we should simply avoid the type check in config for this case, but it makes validation less strict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to prefix a processor here? Referencing the envelope bar with float: prepended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the thing is, without the float cast in the env var retrieval, the service would not receive a float, but a string. So float_node not accepting %env(FLOATISH)% is expected to me.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Jun 1, 2018
@ro0NL
Copy link
Contributor Author

ro0NL commented Jun 3, 2018

bc break resolved, instead of using a string typed placeholder it now preserves the actual env type

@nicolas-grekas
Copy link
Member

Thank you @ro0NL.

@teohhanhui
Copy link
Contributor

Will you add any tests to prevent regressions? :D

@ro0NL
Copy link
Contributor Author

ro0NL commented Jun 19, 2018

@teohhanhui what do you propose? tests are updated as such ...

@teohhanhui
Copy link
Contributor

Sorry, I somehow overlooked that. 🙇‍♂️

@SoboLAN
Copy link

SoboLAN commented Oct 30, 2018

I'm sorry, but this just broke my project and I had to spend like a few hours trying to figure out what was going on.

In my config files I had stuff like:

some_bundle:
    key1:
        subkey:
            value: '%env(MY_URL)%'

    key2:
        subkey:
            value: '%env(MY_OTHER_URL)%'

Those env-vars were defined in .env file. And it worked perfectly fine.

Upgrading symfony/dependency-injection from 4.1.0 to 4.1.6 broke it because now the configuration validation in that 3rd-party bundle complains that those values are not strings.

Only by adding the string: suffix was I able to warmup Symfony's cache.

Breaking BC like this is NOT OK, especially when incrementing only patch version !!

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 30, 2018

it had to be done to prevent another BC break between 3.x and 4.x: #27455

so 4.1.0 is the wrong behavior, and fixed as of 4.1.6.. but i understand being in between was not convenient for you :(

symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Mar 27, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[DI] Deprecate non-string default envs

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes-ish
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes
| Tests pass?   | no    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27680, symfony/symfony#27470 (comment)
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

This is a failing test to further clarify the issues raised in #27680

So given symfony/symfony#27680 (comment)

> We should be sure this solves a real-world issue.

I think it solves a real bug :)

Commits
-------

2311437c9f [DI] Deprecate non-string default envs
fabpot added a commit that referenced this pull request Mar 27, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[DI] Deprecate non-string default envs

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes-ish
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes
| Tests pass?   | no    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27680, #27470 (comment)
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

This is a failing test to further clarify the issues raised in #27680

So given #27680 (comment)

> We should be sure this solves a real-world issue.

I think it solves a real bug :)

Commits
-------

2311437 [DI] Deprecate non-string default envs
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.

6 participants