Closed
Description
Symfony version(s) affected: 4.4.9, 5.0.9, 5.1.0
Description
Since the last point release (on 4.4, 5.0 and 5.1 branches), I get the following exception when calling submit
on a Symfony Form where the validation for some field in a subform failed:
Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException: Could not parse property path "children[[salutation]].data". Unexpected token "]" at position 21.
vendor/symfony/property-access/PropertyPath.php:111
vendor/symfony/form/Extension/Validator/ViolationMapper/ViolationPath.php:55
vendor/symfony/form/Extension/Validator/ViolationMapper/ViolationMapper.php:52
vendor/symfony/form/Extension/Validator/EventListener/ValidationListener.php:55
vendor/symfony/event-dispatcher/EventDispatcher.php:264
vendor/symfony/event-dispatcher/EventDispatcher.php:239
vendor/symfony/event-dispatcher/EventDispatcher.php:73
vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php:44
vendor/symfony/form/Form.php:671
I am not sure if the bug is on my end or in Symfony, all I can say is that it used to work fine up until 4.4.8, in 4.4.9 it broke, so I'm guessing it might be related to #36865 ?
How to reproduce
It's kind of a custom setup, so making a reproducable sample could take a while. But like I said, I'm not even sure if it's a bug on my end or in Symfony, so maybe someone has an idea off the top of their heads?
Activity
matthieu-viel commentedon Jun 1, 2020
Similar issue for me:
Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException: PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse path "parent.all[myfield].data" at property "all". in .../vendor/symfony/property-access/PropertyAccessor.php:327
Working fine after downgrade 4.4.9 to 4.4.7
silverbackdan commentedon Jun 1, 2020
Hi, this has become an issue for me as well.
I'll give you my reproduction as it is failing in a test.
NestedType.php
ChildType.php
Path failed to parse:
children[children].children[[1]].children[name].data
$formData:
Triggered by:
There are some additional unrelated parts in this code, such as the second CollectionType in the root form type. Nor does it matter if the validation fails on just 1 child and that is the first defined in the $formData.
I hope this is clear enough. Sorry I'm rushing writing this a little so please come back to me if something isn't clear or I can do adjustments in my test to double check things quickly for you.
The violation message that is being triggered (correctly) is
Please provide your name
from theChildType
classThis looks to have been a change made in the most recent patch of version 5.0 as well as forcing the 5.0.9 release also fails. 5.0.8 form component is working with 5.1 on other components.
As you'd expect the double square brackets in the property path is the issue and should be
children[children].children[1].children[name].data
in my instance.silverbackdan commentedon Jun 1, 2020
$fieldPropertyPath = \is_object($data) ? 'children[%s]' : 'children%s';
This check is performed twice on different lines.
https://github.com/xabbuh/symfony/blob/b819d94d1413e426237f35e6b6eddbc380dbccf9/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L75
https://github.com/xabbuh/symfony/blob/b819d94d1413e426237f35e6b6eddbc380dbccf9/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L103
In my case, the object is a doctrine
ArrayCollection
which is why I think the$fieldPropertyPath
property is including the square brackets when it shouldn't...Or
$field->getPropertyPath()
should return the path without additional square brackets.flack commentedon Jun 1, 2020
to confirm @silverbackdan's theory, I change https://github.com/xabbuh/symfony/blob/b819d94d1413e426237f35e6b6eddbc380dbccf9/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L103 to look like this:
That seems to fix the problem for me. It's probably not the right way to fix this, but at least it looks like that line is somehow problematic
bug #11542 [Maintenance] Add conflict to the 4.4.9 version of symfony…
Amunak commentedon Jun 2, 2020
Can confirm, similar issue here: I have a PriceType inside of a form, and it consists of a NumberType and a ChoiceType. When I put an invalid value for the ChoiceType, I get this exception when I submit the form:
Could not parse property path "children[price].children[[currency]]". Unexpected token "]" at position 35.
Add workaround for symfony/symfony#37027
flack commentedon Jun 2, 2020
@xabbuh I was looking at
https://github.com/xabbuh/symfony/blob/b819d94d1413e426237f35e6b6eddbc380dbccf9/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php#L103
a bit longer, and I don't understand how that
is_object()
part can work reliably. If you look atsymfony/src/Symfony/Component/Form/Form.php
Lines 223 to 233 in 608b770
$parent
isn't necessarily the same as the$form
where$data
came from. So at least ifgetInheritData
is true for$parent
, you could get double brackets I thinkXen3r0 commentedon Jun 3, 2020
Hello, i have same problem with Symfony 3.4.41 :
Could not parse property path "children[controles].children[[0]]". Unexpected token "]" at position 32.
xabbuh commentedon Jun 3, 2020
I am currently looking into #37025. The fix for that issue might this one too. But in the meantime it would be nice if anyone of you could create a small example application allowing to reproduce this specific error so that we can then check if both issues will be fixed.
matthieu-viel commentedon Jun 3, 2020
in my case it is just a date field validation depending on another one:
kl3sk commentedon Jun 3, 2020
I can confirm this error on Symfony 5.0.9:
xabbuh commentedon Jun 3, 2020
Could you all please check if #37085 does fix this issue by chance too?
flack commentedon Jun 3, 2020
@xabbuh I tried it and it does fix the original error. However, I now get duplicate validation error messages:
in 5.0.8 and earlier this worked as expected (i.e. just one error message, not one for every child)
xabbuh commentedon Jun 3, 2020
I am afraid we will need an example application to be able to reproduce this.
flack commentedon Jun 3, 2020
alright, I'll try to put something together later today
kl3sk commentedon Jun 3, 2020
@xabbuh for me your fix doesn't raise the error anymore.
Everything works again thanks.
Hope for a quick merge, to be able to update my staging app.
flack commentedon Jun 3, 2020
@xabbuh it turns out that the duplicate errors happened because I didn't apply the patch correctly apparently, so all is well in the end, sorry for the noise!
At least I got a reproducer for the original issue out of it:
https://github.com/flack/sf37027
validate subforms in all validation groups
bug #37085 [Form] properly cascade validation to child forms (xabbuh)