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
[Form] Usage of Valid
constraint on simple form type breaks property path resolving
#38039
Comments
Thanks for opening this issue. I agree that there is at least some confusing behavior. Your example greatly allows to reproduce it and I am currently trying to understand what is going. |
see #39333 |
…ta (lchrusciel, xabbuh) This PR was merged into the 4.4 branch. Discussion ---------- [Form] do not apply the Valid constraint on scalar form data | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #38039 | License | MIT | Doc PR | #SymfonyHackday Commits ------- 453bb3e do not apply the Valid constraint on scalar form data 41b9457 [Test] Reproduce issue with cascading validation
Great! Thank you a lot :) As you've used my test case, does it mean I've become a Symfony contributor? :D |
For the record, this seems to have been broken in #36865. Previously, we didn't properly cascade into nested forms which means that misconfigurations like the one from the failing test case went unnoticed. @lchrusciel Yes, congratulations to your first contribution. :) |
Symfony version(s) affected: ^v3.4.41, ^v4.4.9, ^v5.0.9
Description
Hello folks 👋
I'm bringing to you kind of edge case. Since v3.4.41(and upmerged releases) usage of
Valid
constraint on simple form types (relating directly to the field instead of encapsulating another object) like ChoiceType, TextType, or IntegerType breaks property path resolution of other fields with aValid
constraint. This happens only if a particular field passes validation, and another field is failing. Everything works as expected if both fields are valid or invalid. As a result, the error message cannot be displayed on the right field, though the form is still correctly validated.To illustrate this issue, let's validate ReviewForm from Sylius. It contains 4 fields: rating, title, description, and author. Rating(for whatever reason) and author have defined
'constraints' => Valid()
. If one would submit an empty form, this is the result:and the validator calls:
everything works as expected.
However, if the rating field would be filled, this is the current result:
and the validator calls:
As you can see, in the second example,
children[author].data.email
is replaced with[author].data.email
, which cannot be mapped to the form.How to reproduce
The bug is reproduced here: 053d8fb.
In the attached commit, only one test will fail with the following result:
Possible Solution
I assume there is one wrong if statement in
FormValidator
, which be fixed. Nonetheless, I wasn't able to spot it.Since I've fixed our build by removing the
new Valid()
constraint, I'm not sure if I should commit more energy into it. I can help you with solving it if you find this particular problem worth solving and if you give me some guidance.Additional context
The bug was introduced somewhere here: symfony/form@v4.4.8...v4.4.9, probably by this commit: symfony/form@48ec675
The problem may be solved on our end with the removal of probably unnecessary
new Valid()
constraint.I'm openining this issue, as it is affected by wrong configuration in the first place and I'm not sure if there is a point in fixing it. Nevertheless, the "wrong" configuration was working properly since November 2016 and since version 3.0.0 until version 4.4.9.
The text was updated successfully, but these errors were encountered: