-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] respect groups when merging constraints #21183
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
Conversation
xabbuh
commented
Jan 6, 2017
Q | A |
---|---|
Branch? | 2.7 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #20853 |
License | MIT |
Doc PR |
On a dirst glance this still breaks the intention as if you validate Child still the parent constraints are validated as well, right? But as I understand the logic only if you apply Default as group the parent constraints are validate as well, otherwise only the constraints of the specific class are validated which is the onl way to provide full flexibility. The actual issue is that you cannot use Default as group in the GroupSequence. |
Well, I think that merging symfony/symfony-docs#7249 was a mistake I made. At least, by looking at the rest of the code, it seems to me that validating constraints from the parent class to was intended when validating a sub class. I am not sure if I fully understand your issue. So if you had a test case of which you think it should pass, but that is still failing, I would be happy to look at it. |
Initially when documenting the inheritance I thought validating Child would validate the Parent as well. When I tested it now again I figured out it is not like that which makes somehow sense as then you would never be able to just validate the child constraints as Default validates both, Parent just the Parent constraints and Child again both. I did extensive tests and sent a mail to Bernhard regarding the original intention but did not get any feedback. In any case we need to be careful, the current implementation is entirely broken and a BC break which should be reverted. Your fix will still be a BC break for those relying on zhe case wheere you just want to validate the Child constraints. I do not know if that is the case in real wirld apps. I will try your fix the next days, most likely it will fix the wrong groups issue, but I am concerned regarding the BC break. I hope you can understand the issue now? Did you find anything related to the inheritance? Maybe you can reach out to Bernhard? |
But is that really a use case? The problem with this approach is that you then easily could break applications by moving class properties to a base class. Everywhere else in PHP the property would still look like it's part of the object being validated while the validator doesn't agree with this. IMO, this is not how it should behave. It's different from cascading validation to nested objects because nested object are not really part of the object, but are just associated objects while properties from parent classes are just part of the unit we are looking at (there's noch such difference in OOP when looking at an object from the outside).
I agree that this is a BC break. However, I also see the issue it fixes. We just need to be careful not to blindly always add the constraint to the default group.
Well, the
I'll ask him. |
Okay, I just tested it with the BC Break caused in one of my apps, this would fix it. @yakobe Have you had the chance to test this? Does this fix your issues? The other matter is mainly philosophic I guess. When I investigated this I while ago I think My personal favor would be that if you validate It will be a BC break if this was intended previously and we shoudl discuss if we want it Once decided we should then adjust the docs accordingly. |
if (in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) { | ||
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint; | ||
} | ||
|
||
$constraint->addImplicitGroupName($this->getDefaultGroup()); |
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.
Eventually you might have to call that prior to the previous if statement?
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.
That shouldn't make a difference.
This works for my use case. I also do not see a practical use case for only validating Child without Parent. But you guys are right to investigate the impacts. Thanks 👍 |
@xabbuh Any news on this? |
@peterrehm Not yet, let's see what the other @symfony/deciders think about this. |
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 look like a good fix to me 👍
Thank you @xabbuh. |
This PR was merged into the 2.7 branch. Discussion ---------- [Validator] respect groups when merging constraints | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20853 | License | MIT | Doc PR | Commits ------- 9a60057 respect groups when merging constraints
This PR was merged into the 2.7 branch. Discussion ---------- [Validation] Revert #7249 This reverts commit 6c3ff5e since due to symfony/symfony#21183 the logic is meanwhile changed. Commits ------- 3250ed4 Revert "Fixed wrong inheritance information"
Symfony Validator claims to follow JSR-303, so compliance should be the priority. |
@teohhanhui What does JSR-303 say in this regard? |
@peterrehm I'm not sure... Someone needs to take a look, and then we'll know what's the right solution. I had to refer to the JSR-303 spec the last time, and it wasn't fun. 😆 |
states: So I think the now modified change makes it according to JSR-303. |