[Validator] UniqueValidator - normalize before reducing keys#54137
Merged
fabpot merged 1 commit intosymfony:6.4from Mar 9, 2024
Merged
[Validator] UniqueValidator - normalize before reducing keys#54137fabpot merged 1 commit intosymfony:6.4from
fabpot merged 1 commit intosymfony:6.4from
Conversation
|
Hey! Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "6.4". Cheers! Carsonbot |
xabbuh
approved these changes
Mar 7, 2024
Member
|
For 5.4? |
Member
|
@xabbuh the original PR was merged in 6.1 |
Member
fabpot
approved these changes
Mar 9, 2024
2e13553 to
77df90b
Compare
Member
|
Thank you @Brajk19. |
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.
In #42403 checking for uniqueness of certain collection keys was enabled. Method
UniqueValidator::reduceElementKeysremoves all keys which are not specified.Problem is that this happens before normalization, which in my opinion is not great because that method accepts array argument and if i have some object (DTO), TypeError will be thrown.
Example:
Because normalization will happen after
reduceElementKeysthis will be thrown:TypeError: Symfony\Component\Validator\Constraints\UniqueValidator::reduceElementKeys(): Argument #2 ($element) must be of type array, ...\ChildDTO given, called in .../UniqueValidator.php on line 48If
$element = $normalizer($element);is executed beforereduceElementKeysit would enable using Assert\Unique with array of objects when correctly normalized