Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@mpiot

Description

@mpiot
Issue body actions

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) ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ValidatorhasPRA Pull Request has already been submitted for this issue.A Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.