Skip to content

[Validator][GroupSequence] GroupSequence validation ignores PropertyMetadata of parent classes #19387

Closed
@senaria

Description

@senaria

GroupSequences do not seem to run property validations of parent classes. Class constraints are recognized correctly and run without problem but not those on the Parent::$property's.

For example:

/**
 * @Assert\ParentClassConstraint()
 */
class Parent
{
    /**
    * @Assert\NotNull()
    */
    protected $property;
}

/**
 * @Assert\ChildClassConstraint()
 * @Assert\GroupSequence({"Child", "Extra"})
 */
class Child extends Parent
{
   /**
    * @Assert\NotNull(groups={"Extra"})
    */
    private $anotherProperty;
}

When I run the validation on Child the group sequence will run @Assert\ParentClassConstraint() of Parent, @Assert\ChildClassConstraint() of Child and @Assert\NotNull(groups={"Extra"}) of Child. However, it will not run @Assert\NotNull() of Parent

I think I found the cause of the problem: \Symfony\Component\Validator\Mapping\ClassMetadata::mergeConstraints Does not seem to add them to the PropertyMetadata::$constraintsByGroup.

I will create a patch with tests to see if i can suggest a fix.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions