Skip to content

fix(symfony): filter nested constraint groups in Sequentially/Compound#8223

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/7777-sequentially-nested-groups
Jun 2, 2026
Merged

fix(symfony): filter nested constraint groups in Sequentially/Compound#8223
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/7777-sequentially-nested-groups

Conversation

@soyuka

@soyuka soyuka commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #7777.

ValidatorPropertyMetadataFactory::getPropertyConstraints() expanded Composite::getNestedConstraints() for Sequentially/Compound without filtering by the active validation group. Because Symfony's Composite constructor merges nested groups into the parent (union), a parent in Default could carry a nested constraint that only lives in another group.

Reporter case:

#[Assert\Sequentially([
    new Assert\NotBlank(groups: ['some group']),
    new Assert\Range(min: '0.01'),
])]
private ?string \$someField = null;

Sequentially.groups becomes ['some group', 'Default'] (union from nested). For Default validation, findConstraints('Default') returned Sequentially, then we yielded every nested constraint — including the NotBlank that only belongs to 'some group' — and isRequired() flagged the field as required in the OpenAPI schema.

The fix filters each nested constraint by \in_array(\$validationGroup, \$nestedConstraint->groups, true). Symfony's Constraint::addImplicitGroupName() already propagates the class default group only to constraints already in Default, so explicit non-Default nested groups remain excluded — semantics match validator runtime behavior.

Test plan

  • New fixture DummySequentiallyValidatedEntityWithNestedGroups reproduces the reporter's constraint shape.
  • New unit test testSequentiallyConstraintDoesNotMarkRequiredFromNestedConstraintWithDifferentGroup fails before the fix (required=true), passes after (required=false).
  • Existing testCreateWithSequentiallyConstraint and testCreateWithCompoundConstraint still pass — restriction extraction is unaffected for groupless nested constraints.
  • Full src/Symfony/Tests/Validator/ suite green.

ValidatorPropertyMetadataFactory expanded Composite::getNestedConstraints()
unfiltered. A nested NotBlank(groups: ['some group']) inside a Sequentially
(in Default via Composite group union) leaked into the Default expansion
and falsely marked the property required in the OpenAPI schema.

Filter nested constraints by the active validation group.

Closes api-platform#7777
@soyuka soyuka merged commit 0e0c58b into api-platform:4.3 Jun 2, 2026
105 of 108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant