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
Recently, I upgraded my Symfony version from 6.3 to 7.2. I've noticed that the Unique Validator stopped working when validation groups were present.
Code without groups, the validator catches the error and prevents the duplicate in the database:
<?phpnamespaceApp\Document;
useDoctrine\ODM\MongoDB\Mapping\AnnotationsasMongoDB;
useDoctrine\Bundle\MongoDBBundle\Validator\Constraints\UniqueasMongoDBUnique;
#[MongoDB\Document]
#[MongoDBUnique(fields: ['email'])]
class User
{
#[MongoDB\Id]
protectedstring$id;
#[MongoDB\Field(type: 'string')]
protectedstring$email;
}
Validation groups in use, the validator is not executed, causing a duplicate in the database:
<?phpnamespaceApp\Document;
useDoctrine\ODM\MongoDB\Mapping\AnnotationsasMongoDB;
useDoctrine\Bundle\MongoDBBundle\Validator\Constraints\UniqueasMongoDBUnique;
#[MongoDB\Document]
#[MongoDBUnique(fields: ['email'], groups: ['registration'])]
class User
{
#[MongoDB\Id]
protectedstring$id;
#[MongoDB\Field(type: 'string')]
protectedstring$email;
}
Current behavior
The Unique validator is not executed when the validation groups are present.
Expected behavior
The Unique validator should work with and without validation groups.
How to reproduce
Install Symfony 7.2 with doctrine/mongodb-odm-bundle.
Create a document with validation groups (example above).
Configure the form to use the validation group:
Try to submit the form twice using the same email. It will create two documents with the same email, but it should display a validation error on the second attempt.
The text was updated successfully, but these errors were encountered:
This is the PR introducing said feature symfony/symfony#38662. Not gonna lie, changing arguments order on Symfony's end would be the easiest way but it may be way too late for that as the feature was shipped in 7.1
Bug Report
Summary
Recently, I upgraded my Symfony version from 6.3 to 7.2. I've noticed that the Unique Validator stopped working when validation groups were present.
Code without groups, the validator catches the error and prevents the duplicate in the database:
Validation groups in use, the validator is not executed, causing a duplicate in the database:
Current behavior
The Unique validator is not executed when the validation groups are present.
Expected behavior
The Unique validator should work with and without validation groups.
How to reproduce
Install Symfony 7.2 with
doctrine/mongodb-odm-bundle
.Create a document with validation groups (example above).
Configure the form to use the validation group:
Handle form submission in the controller:
Try to submit the form twice using the same email. It will create two documents with the same email, but it should display a validation error on the second attempt.
The text was updated successfully, but these errors were encountered: