-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Duplicated errors for constraints when using several validation groups #4427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
this is really weird. When trying again, I don't receive the exception anymore, but I have a duplicated error message |
actually the validation seems to be called twice even without |
Can you please check whether #4431 fixes this? |
It does not fix the issue. Btw, by putting a dump call in the validator, I saw that the validation is called twice. |
Ok. Can you give me any instructions to reproduce this? |
I found the issue when replacing our custom password validation in FOSUserBundle by the Symfony 2.1 constraint. I just pushed my |
I extracted ProfileFormType into a test project and replaced the UserPassword constraint by MinLength. The validator is called exactly once. Are you sure you're not binding twice? |
The only place using the UserPassword constraint is the form type. And other constraints (coming from the Validator mapping) are not duplicated for the same form. |
If you replace UserPassword by MinLength, is it also validated twice? |
yes, MinLength also duplicates the error message when applying it on the unmapped field |
I fear you have to debug it then. I cannot reproduce. |
@bschussek I looked at the code and I found the issue: it is not only for unmapped fields but for all fields when using the |
The related code is https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L69 |
Commits ------- c0a5207 [Form] Prevented duplicate validation of form constraints Discussion ---------- [Form] Prevented duplicate validation of form constraints Bug fix: yes Feature addition: no Backwards compatibility break: *yes* (at least that can be argued. I consider it a correction of incorrectly implemented functionality) Symfony2 tests pass: yes Fixes the following tickets: #4427 Todo: -
Was this resolved? I have the following validation: Vivo\PageBundle\Entity\Page:
properties:
pageTitle:
- NotBlank:
groups:
- base_validation
- page_model
- Blank:
groups:
- base_validation
- page_model Form: ...
'validation_groups' => array('base_validation', 'page_mode')
... I get duplicate error messages. Is this related? page:
pageTitle:
ERROR: This value should be blank.
ERROR: This value should be blank. |
@trsteel88 I’ve experienced the same behavior and I think that is normal (meaning it wouldn’t be classified as a bug). What I do to avoid multiple errors is to only set one validation_group in the form class. But it should also be possible to just set one group in the validation mapping...so try only adding base_validation and not page_model in your yml. |
When adding a violation error on an unmapped field, the ViolationMapper creates a PropertyPath with an empty string, which is invalid and throws an exception.
Code to reproduce the issue:
The text was updated successfully, but these errors were encountered: