Skip to content

[Validator] Valid constraint do not use Default as default group #17338

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
mpiot opened this issue Oct 11, 2022 · 3 comments
Closed

[Validator] Valid constraint do not use Default as default group #17338

mpiot opened this issue Oct 11, 2022 · 3 comments
Labels
hasPR A Pull Request has already been submitted for this issue. Validator

Comments

@mpiot
Copy link
Contributor

mpiot commented Oct 11, 2022

The Valid constraint default group is no Default but null.

If we defined something like:

  class User
  {
    #[Assert\NotBlank(groups: ['create'])]
    #[Assert\Length(min: 4, groups: ['create'])]
    protected $firstName;

    #[Assert\NotBlank(groups: ['create'])]
     protected $lastName;

    #[Assert\Valid]
    private Collection $addresses;
  }

  class Address
  {
    #[Assert\NotBlank]
    protected $street;

    #[Assert\NotBlank]
    #[Assert\Length(max: 5)]
    protected $zipCode;
  }

When we validate the User with the create validation groups, it also validate Address, because the Valid constraint define the validation groups to null instead of Default.

To have something that work as attended we must define Default in Valid constraint:

       #[Assert\Valid(groups: ['Default'])]
        private Collection $addresses;
  }

It appear that this behavior is attended because there is a test to check that the Valid default group is null instead of Default.

There is no info about that behavior in the documentation, and why this specific constraint do not have Default as default group. I don't know why null is the default value here, just pass some times to find why the behavior is not the attended one (expect Default group like others).

Maybe @xabbuh you can help us about it (symfony/symfony#21111) ?

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link
Collaborator

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@xabbuh xabbuh added hasPR A Pull Request has already been submitted for this issue. and removed Stalled labels Nov 6, 2023
@OskarStark
Copy link
Contributor

Closed via #19112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hasPR A Pull Request has already been submitted for this issue. Validator
Projects
None yet
Development

No branches or pull requests

4 participants