-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Variable "this" has value of null in an "Expression" validation constraint inside an "All" validation constraint #20477
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
In your case, getting the ParentClass instance would be wrong. When the |
@stof Well, it makes sense and I agree with your reasoning. However I think the variable Also I found out, that the expression variables in class-level constraints are assigned inconsistently depending if they are defined within the
The validation passes, since the expression is evaluated as Then it would be expectable for the next constraint to pass too:
However, it's definitely not, since in this case I think in both cases, |
I encountered the same bug expecting to access to the object being validated through I think the context should not be lost when |
… constraint (ostrolucky) This PR was merged into the 2.7 branch. Discussion ---------- [Validator] Fix access to root object when using composite constraint | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12315, #20477, #21706 | License | MIT | Doc PR | Commits ------- b18cdcf [Validator] Fix access to root object when using composite constraint
Uh oh!
There was an error while loading. Please reload this page.
I have possibly found a bug in the Validator component when combining these two constraints: Expression and All. I'm going to show it on an example:
Considering these two classes:
and
With the following validation rules stored in
validation.yml
:I would like to achieve to forbid assigning the parent's name to children. So the
getName()
method of the parent should return a distinct value fromgetName()
methods of all children.However after trying to validate an instance of
ParentClass
constructed like this:A RuntimeException is thrown with the following message:
As I figured out, the variable value is correctly assigned to child objects, however the variable this in the expression has a value of null. I would expect a reference to the parent object in this variable, regarding to the documentation:
Symfony 3.1.6, PHP 7.0.8, Linux Mint 18
The text was updated successfully, but these errors were encountered: