symfony: InvalidPropertyPathException: Could not parse property path

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?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Could you all please check if #37085 does fix this issue by chance too?

@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

@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.

alright, I’ll try to put something together later today

Hello, i have same problem with Symfony 3.4.41 :

Could not parse property path “children[controles].children[[0]]”. Unexpected token “]” at position 32.

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.

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:

$fieldPropertyPath = \is_object($data) && !$data instanceof \Iterator ? 'children[%s]' : 'children%s';

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