You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I make nested constraints AtLeastOneOf, the validator will skip all violations.
The Symfony validator employs two factories for initializing an instance of a constraint validator:
Symfony\Component\ValidatorConstraintValidatorFactory - creates a new instance of the validator and caches it as an array.
Symfony\Component\ContainerConstraintValidatorFactory - retrieves the validator from the DI container. As each unique service in a container is passed by reference, each validator is initialized only once.
The issue arises when creating a nested constraint, such as AtLeastOneOf. At line 752 of RecursiveContextualValidator, a new context for this validator is initialized, which is the root cause of the bug.
How to reproduce
To reproduce this bug, you can use the following code:
Symfony version(s) affected
6.4
Description
When I make nested constraints AtLeastOneOf, the validator will skip all violations.
The Symfony validator employs two factories for initializing an instance of a constraint validator:
The issue arises when creating a nested constraint, such as
AtLeastOneOf
. At line 752 ofRecursiveContextualValidator
, a new context for this validator is initialized, which is the root cause of the bug.How to reproduce
To reproduce this bug, you can use the following code:
As we can see, incorrect data exists for the key
AtLeastOneOfNested1
, but the validator skips these violations.Possible Solution
A possible solution is to consistently initialize a new instance of
AtLeastOneOfValidator
within a factory.Additional Context
No response
The text was updated successfully, but these errors were encountered: