-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[OptionResolver] (Default) null values are not allowed since 2.6 #12809
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
Comments
I can confirm this BC break that's new in 2.6. I can reproduce it exactly with this code: use Symfony\Component\OptionsResolver\OptionsResolver;
$resolver = new OptionsResolver();
$resolver->setDefaults([
'my_option' => null,
]);
$resolver->setAllowedValues([
'my_option' => ['one', 'two', 'three'],
]);
$options = $resolver->resolve(array()); With the 2.5 branch, I receive no error. With 2.6.1,
I confirmed that the BC break was introduced at #11716, which I believe was accidental. I think we should fix this to the old behavior. Thanks @4rthem for the report! |
@webmozart Can you have a look at this one? |
I can confirm this problem with Symfony 2.6.1. It breaks HWIOAuthBundle when using Google login and gives the error: "The option "access_type" with value null is invalid. Accepted values are: "online", "offline"." |
Well, this is indeed a BC break in one case: when your default value is not allowed by your validation of allowed values. However, this means that your option resolution forbids people to pass you the option with its default value explicitly. This looks like a broken setup IMO. |
I also think the old behavior was not intended to work and just worked accidentally. The current behavior is the better one. To support the use-case you only have to add |
Although I agree that throwing the exception is certainly more "correct", and HWIOAuthBundle is clearly doing the wrong thing -- From an end user perspective, the new check prevents anyone from upgrading to 2.6 until every dependency they have that relies on the old behavior is updated. I've had to require "symfony/symfony": "2.5.*" in all my projects pending a resolution. I've submitted hwi/HWIOAuthBundle#710 since I don't think it's logged there. |
@jasonhanley brings up a good point. Is there any reason we shouldn't re-allow null now and deprecate this "feature" for removal in 3.0? |
I'd rather consider this a bug that was fixed. And reintroducing a bug seems bad. |
Closing because it was a bug fix in @stof and my opinion. I added a test to keep this logic in place. |
@weaverryan The BC break is not about null specifically. It is about any mismatch between the default value and the allowed values. Symfony 2.5 was also allowing you to defined the allowed values as being |
…s that default to null (Tobion) This PR was merged into the 2.6 branch. Discussion ---------- [OptionsResolver] added test for allowed values and types that default to null | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | - | License | MIT | Doc PR | - Added test to keep logic as experienced in #12809 Commits ------- 0b42cad [OptionsResolver] added test for allowed values and types that default to null
With this configuration, the option
my_option
must be defined because it can't be null.Is this wanted? I can't find any note about this on the upgrade guide.
This causes an
InvalidOptionsException
with HWIOAuthBundle. We now have to define all options or wait for a bundle update: see options configuration whereaccess_type
was optional.The text was updated successfully, but these errors were encountered: