Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] Propagate embedded groups for collection validator#25888
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
hhamon commentedJan 23, 2018
/propage/propagate/ in your commit message :) |
| foreach ($valueas$key =>$element) { | ||
| $validator->atPath('['.$key.']')->validate($element,$constraint->constraints); | ||
| $validator->atPath('['.$key.']')->validate($element,$constraint->constraints,$constraint->groups); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Shouldn't this be$context->getGroup() too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
To give more context: This implementation suffers the same implications as discussed in#23480 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
TheComposite constraint is special,All andCollection inherit it.
The rules are explained herehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/Composite.php#L34-L48, we need to not break them.
So I tend to agree with@xabbuh that we should not just rely on thegroups public property of nested constraints to resolve any issue.
| ->inContext($context) | ||
| ->atPath('['.$field.']') | ||
| ->validate($value[$field],$fieldConstraint->constraints); | ||
| ->validate($value[$field],$fieldConstraint->constraints,$fieldConstraint->groups); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
see above
backbone87 commentedJan 24, 2018
can we please close either#23480 or this one? both address the same problem and propose the same fixing strategy. Using $contraint =newCollection(['fields' => ['key' =>newLength(['min' =>6, groups => ['b']]), ],'groups' => ['a','b'],]);$validator->validate(['key' =>'value' ],$contraint,'a'); From my point of view we have a 2 possibilities:
|
HeahDude commentedJan 24, 2018
I'm not sure there is really an issue here, just a misusage while not being aware ofhttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/Composite.php#L34-L48 (documentation issue). Actually#17675 (comment), could be written: /** * @Collection( * fields={ * "foo" = { * @NotBlank(groups={"foo"}), * @Length(min="2", groups={"bar"}), * @Length(min="4", groups={"baz"}), * } * }, * groups={"foo", "bar", "baz"} * ) */ And this should be the way to go IMHO. |
backbone87 commentedJan 24, 2018
This doesnt work with grp sequences |
HeahDude commentedJan 25, 2018
So this is what needs to be fixed :). Could you please update your tests here@blazarecki? |
blazarecki commentedJan 25, 2018
Yes I'll do that. |
backbone87 commentedJan 25, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@blazarecki imho there is nothing wrong with grp sequences. the possible fix path are described in my comment above. Despite the comment inhttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/Composite.php#L34 different grps for composite contraint and nested constraints just dont work. If we dont want to change anything, then my proposed solution 1 is a good way. |
fabpot commentedMay 28, 2018
artursvonda commentedAug 2, 2018
Any help needed with this one? Comments seem to be addressed and tests passing. |
blazarecki commentedAug 2, 2018
@artursvonda tell me if I need to change something. |
artursvonda commentedAug 2, 2018
HeahDude left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As said in my previous comment, there is no issue to fix as is.
Tests must be adapted to check if group sequences fail in some way as@backbone87 claimed.
Otherwise we can close here.
| foreach ($valueas$key =>$element) { | ||
| $validator->atPath('['.$key.']')->validate($element,$constraint->constraints); | ||
| $validator->atPath('['.$key.']')->validate($element,$constraint->constraints,array($context->getGroup())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Only subsets are allowed on traversable node. This would be a broken feature not a bug fix.
| newRange(array('min' =>1,'groups' =>'bar')), | ||
| ), | ||
| ), | ||
| 'groups' =>'foo', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This test is wrong and breaks BC. Groups should bearray('foo, 'bar') here, and the test would be green already, without the changes introduced in this PR.
| array(array('foo'),array('foo','bar'),array('foo','bar')), | ||
| array(array('foo'),array('bar'),array('foo','bar')), | ||
| array(array('foo'),array('foo'),array('foo','bar')), | ||
| array(array('foo'),array('foo'),array('foo')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You're passingfoo andbar for every case of collection groups above, but not here, while there is no bar group on any entry.
Are there some cases actually failing before your changes?
| ), | ||
| ), | ||
| ) | ||
| )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If there is no group set on the collection contraint, group on entry should never be validated (since it won't ever be a subset).
| newRange(array('min' =>5,'minMessage' =>'Group bar','groups' =>'bar')), | ||
| ), | ||
| ) | ||
| )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same here.
Aliance commentedAug 15, 2018
xabbuh commentedDec 7, 2018
Thank you all for your input and working on this. This is finally going to be fixed in#29499. |
This PR was merged into the 3.4 branch.Discussion----------[Validator] Fixed grouped composite constraints| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#17675,#25888,#23480| License | MIT| Doc PR | ~From Lisbon :). Thanks@stof,@xabbuh for your help to finally fix this old issue.Commits-------b53d911 [Validator] Fixed grouped composite constraints
This PR fix the issue describe in#17675
This PR is related to#17696