8000 [Validator] All validation groups are not used on embedded constraints in a collection constraint · Issue #17675 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] All validation groups are not used on embedded constraints in a collection constraint #17675

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

Closed
blazarecki opened this issue Feb 3, 2016 · 5 comments

Comments

@blazarecki
Copy link

Hi,

I don't know if it's a bug but it seem that all embedded constraints of a collection constraint are not applied when using validation groups.

I think that only the first validation group passed to the validator is used and the other are omitted.

With the following example if $config is equal to ['foo' => 'a'] then with validation groups:

  • ['foo', 'bar', 'baz'] we have 0 violation (NotBlank)
  • ['baz', 'bar', 'foo'] we have 1 violation (Lenght(min="4"))
  • ['bar', 'baz', 'foo'] we have 1 violation (Lenght(min="2"))
    /**
     * @Collection(
     *     fields={
     *          "foo" = {
     *              @NotBlank(groups={"foo"}),
     *              @Length(min="2", groups={"bar"}),
     *              @Length(min="4", groups={"baz"})
     *          }
     *     }
     * )
     */
    public $config;

Here the complete gist with the tests : https://gist.github.com/blazarecki/5dcb754be22dae4f0e53

Any idea ?
Thanks.

@blazarecki blazarecki changed the title [Validation] All validation groups are not used on embedded constraints in a collection constraint [Validator] All validation groups are not used on embedded constraints in a collection constraint Feb 3, 2016
@backbone87
Copy link
Contributor

I think the problem is the caching of already validated contraints. So the @Collection gets only validated in the first group given.
Can you try:

    /**
     * @Collection(
     *     fields={
     *          "foo" = {
     *              @NotBlank(groups={"foo"})
     *          }
     *     }
     * )
     * @Collection(
     *     fields={
     *          "foo" = {
     *              @Length(min="2", groups={"bar"})
     *          }
     *     }
     * )
     * @Collection(
     *     fields={
     *          "foo" = {
     *              @Length(min="4", groups={"baz"})
     *          }
     *     }
     * )
     */

@blazarecki
Copy link
Author

Thanks you @backbone87 it's work. 👍
For information I have update the gist.

I let this issue open because it seem to be a optimisation issue.

What do you think @dunglas ?

@webmozart
Copy link
Contributor

Thanks for reporting this issue! This looks like a bug to me.

Status: reviewed

@blazarecki
Copy link
Author

I create a PR that fix the issue for collection constraint.
I'll check other composite constraints.

It seem that the bug was introduce in Symfony 2.6

@blazarecki
Copy link
Author

@webmozart I fix the issue in this PR #17696

Can you look at it ?

Thank you.

stof added a commit that referenced this issue 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
@stof stof closed this as completed Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0