fix(symfony): filter nested constraint groups in Sequentially/Compound#8223
Merged
soyuka merged 1 commit intoJun 2, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7777.
ValidatorPropertyMetadataFactory::getPropertyConstraints()expandedComposite::getNestedConstraints()forSequentially/Compoundwithout filtering by the active validation group. Because Symfony'sCompositeconstructor merges nested groups into the parent (union), a parent inDefaultcould carry a nested constraint that only lives in another group.Reporter case:
Sequentially.groupsbecomes['some group', 'Default'](union from nested). ForDefaultvalidation,findConstraints('Default')returnedSequentially, then we yielded every nested constraint — including theNotBlankthat only belongs to'some group'— andisRequired()flagged the field as required in the OpenAPI schema.The fix filters each nested constraint by
\in_array(\$validationGroup, \$nestedConstraint->groups, true). Symfony'sConstraint::addImplicitGroupName()already propagates the class default group only to constraints already inDefault, so explicit non-Default nested groups remain excluded — semantics match validator runtime behavior.Test plan
DummySequentiallyValidatedEntityWithNestedGroupsreproduces the reporter's constraint shape.testSequentiallyConstraintDoesNotMarkRequiredFromNestedConstraintWithDifferentGroupfails before the fix (required=true), passes after (required=false).testCreateWithSequentiallyConstraintandtestCreateWithCompoundConstraintstill pass — restriction extraction is unaffected for groupless nested constraints.src/Symfony/Tests/Validator/suite green.