Skip to content

When expanding Sequentially/Compound constraints, nested constraint groups are not checked #7777

@iva3682

Description

@iva3682

API Platform version(s) affected: 4.2.16

Description
Error in file ValidatorPropertyMetadataFactory.php:186-188:

foreach ($validatorPropertyMetadata->findConstraints($validationGroup) as $propertyConstraint) {
    if ($propertyConstraint instanceof Sequentially || $propertyConstraint instanceof Compound) {
        $constraints[] = $propertyConstraint->getNestedConstraints(); // <-- problem here
    }
}

Chain:

  • getValidationGroups() → returns ['Default'] (when there are no explicit validation_groups in the operation)
  • findConstraints('Default') → finds Assert\Sequentially([...]) because Sequentially itself has no group and belongs to Default ✓
  • getNestedConstraints() → returns all nested constraints without checking their groups
  • Among them it turns out NotBlank(groups: ['some group'])
  • isRequired(NotBlank) → return true

When expanding Sequentially/Compound constraints, nested constraint groups are not checked. getNestedConstraints() returns a raw array without group filtering.

How to reproduce

    #[Assert\Sequentially([
        new Assert\NotBlank(groups: ['some group']),
        new Assert\Range(min: '0.01'),
    ])]
    private ?string $someField = null; <- field will be required in OpenApi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions