Skip to content
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

[Validator] Pass validation groups on Collection validate. #23480

Closed

Conversation

Aliance
Copy link
Contributor

@Aliance Aliance commented Jul 11, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23479
License MIT

Complete description can be found in related issue.

@nicolas-grekas
Copy link
Member

For some reason, Travis did not start. Please add tests also. The "BC break" flag means you should explain what's the precise behavior change, why you think we should still do it, explain why this cannot be done as a new feature on 3.4, with proper BC layer, etc.

@Aliance
Copy link
Contributor Author

Aliance commented Jul 12, 2017

For some reason, Travis did not start.

Because I created a pr into master, and then changed to 2.8. Can you restart them manually?

Please add tests also.

Ok, I will try to find out where they should be.

you should explain what's the precise behavior change

All description in linked issue.

@xabbuh
Copy link
Member

xabbuh commented Jul 12, 2017

Does this not happen on Symfony 2.7?

@Aliance
Copy link
Contributor Author

Aliance commented Jul 12, 2017

@xabbuh I'm using LTS version 2.8, but I can check 2.7 a bit later.

@Aliance
Copy link
Contributor Author

Aliance commented Jul 12, 2017

So, I check all tests, after my fix I have to fix AbstractConstraintValidatorTest:: expectValidateValueAt: now by default the Default validation group is passed to the mock method (see b31795c). Has not added any new tests yet, any ideas the best place for them?

Have no ideas why appveyor build fails, but seems there are some global problems, not because of my code.

While fixing the tests, found another place with the same bug: AllValidator. Fix it too.

@Aliance
Copy link
Contributor Author

Aliance commented Jul 13, 2017

Does this not happen on Symfony 2.7?

I have checked it, the answer is yes, this bug is also actual in Symfony 2.7. I think it will reproduce on 2.5+ (see linked pr in issue)

@Aliance Aliance changed the title [Validation] Pass validation groups on Collection validate. [Validator] Pass validation groups on Collection validate. Jul 13, 2017
@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jul 13, 2017
@nicolas-grekas
Copy link
Member

Can you rebase on 2.7 please?

@Aliance Aliance force-pushed the pass-groups-on-collection-validate branch from 9687609 to 7a8cc0d Compare July 13, 2017 14:03
@Aliance Aliance changed the base branch from 2.8 to 2.7 July 13, 2017 14:03
@Aliance
Copy link
Contributor Author

Aliance commented Jul 13, 2017

@nicolas-grekas done!

So, does it BC break or not? I was not sure, so I mark pr as BC break. But may be it not 🤔

@nicolas-grekas
Copy link
Member

@xabbuh WDYT?

@nicolas-grekas
Copy link
Member

Just noticed that this looks a lot like #17696, maybe the discussion there would help move forward?

@Aliance Aliance force-pushed the pass-groups-on-collection-validate branch from 89f25c2 to 343c8ce Compare July 31, 2017 05:01
@Aliance
Copy link
Contributor Author

Aliance commented Jul 31, 2017

I can't understand, why it pasts about 3 weeks since I've report a bug and make a PR that solves it, but it is still not merged. What should I do to speed up merging it?

@trilobit
Copy link

Hi! I have the same problem with validation groups. Let's merge this pull request.

@trilobit
Copy link

trilobit commented Aug 2, 2017

@nicolas-grekas @xabbuh what do you think?

@xabbuh
Copy link
Member

xabbuh commented Sep 20, 2017

The changes look valid to me. But can you add some test that would fail without them?

@Aliance Aliance force-pushed the pass-groups-on-collection-validate branch from 185b55c to 5c3e710 Compare September 24, 2017 18:36
@Aliance
Copy link
Contributor Author

Aliance commented Sep 24, 2017

@xabbuh I added some test (was taken from related pr), they fails in 2.7 without my fixes:
2017-09-24 21 32 19
2017-09-24 21 31 20

@Aliance
Copy link
Contributor Author

Aliance commented Sep 24, 2017

@fabpot @nicolas-grekas @webmozart please look at my bugfix again and merge it please.

@fabpot
Copy link
Member

fabpot commented Sep 24, 2017 via email

@Aliance
Copy link
Contributor Author

Aliance commented Sep 24, 2017

@fabpot I've already rebased, mb you see the cached commits?

@Aliance
Copy link
Contributor Author

Aliance commented Sep 28, 2017

@fabpot @xabbuh @nicolas-grekas is there something wrong with this pr, why you don't reply to me? :)
Also, please, remove BC break label, this is not BC.

@javiereguiluz
Copy link
Member

@Aliance I've removed the BC Break. About the lack of response, please be more patient. At the moment we're focused on the Symfony 3.4 and Symfony 4.0 feature freeze which ends this weekend. Since your pull request is about a bug fix, we can work on it even during the feature freeze period. Thanks!

@Aliance
Copy link
Contributor Author

Aliance commented Nov 25, 2017

May be someone can take a look at this bugfix now?

@@ -44,12 +44,12 @@ public function validate($value, Constraint $constraint)
$validator = $context->getValidator()->inContext($context);

foreach ($value as $key => $element) {
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints, $constraint->groups);
Copy link
Member

Choose a reason for hiding this comment

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

I asked the same in #17696 too: Don't we have to use $context->getGroup() here to not accidentally widen the validation scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think getters is better than properties, but there is $constraint->constraints not $constraint->getConstraints(). So I wrote the same way.
Should I change only groups, change both or no one?

Copy link
Member

Choose a reason for hiding this comment

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

No, what I mean is fetching the groups from the context but not from the constraint? There may be more groups configured on the constraint than what groups are actually used to validate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, It's not the same. Please see my original issue: #23479
I have attached xdebug screenshots there.
Also I have post a link to my symfony standart fork with easy code, which is broken with current version of Symfony, but it works with my fixes. You can clone it and make sure that $context->getGroup will have only a Default string, while $constraint->constraints will have an array of needed groups: ["info", "Default", "Category] for the Category entity as it was set in validation.yml

Copy link
Member

Choose a reason for hiding this comment

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

You are right that there is still a problem. But just passing the constraints here does not work either. For example, if you take your example project and modify the controller to only run validation in the Default and modify group, the Length constraint will still be evaluated which is only part of the info group.

@nicolas-grekas
Copy link
Member

@Aliance how could we move forward here?

@Aliance
Copy link
Contributor Author

Aliance commented Jan 23, 2018

@nicolas-grekas I have no idea, but 1 year bug in Symfony makes me sad 😢
Does someone has any ideas?

@xabbuh
Copy link
Member

xabbuh commented Jan 23, 2018

see also #25888 which tries to fix the issue too (currently with the same approach)

@artursvonda
Copy link
Contributor

Need any help with finishing this PR? Seems easy enough. Is changing $constraint->groups to fetching group from context only change required here?

@xabbuh
Copy link
Member

xabbuh commented Dec 7, 2018

Thank you all for your input and working on this. This is finally going to be fixed in #29499.

@xabbuh xabbuh closed this Dec 7, 2018
stof added a commit that referenced this pull request Dec 8, 2018
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
@Aliance Aliance deleted the pass-groups-on-collection-validate branch December 8, 2018 16:02
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.

None yet

8 participants