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
Currently, if a form field does not have an equivalent setter or adder and does not use the ['mapped' => false] option, we get a NoSuchPropertyException that complains about a lack of setters or adders when submitting the form. (Later versions of Symfony use a slightly different message, but it's equally uninformative.)
(This is Symfony\Component\PropertyAccess\PropertyAccessor::getReadAccessInfo(), in the method's final else branch.)
That's fine, I guess, but it can be a little bit confusing. I suggest instead using a message like Could not determine access type for property "title" in class "App\Entity\Post". Please either make the corresponding property public, add getters and setters, or set the form type's corresponding field to use a "mapped" value of false.
How to reproduce
Create a form field in a form type that doesn't have a setter or adder associated with it in the equivalent Doctrine entity (where the property should be private), and don't pass any options to the field. Then submit the form. You should get a nice NoSuchPropertyException talking about the missing methods, but it won't mention anything about how to solve the issue if you don't want to add those methods.
Possible Solution
I will modify the part of the PropertyPathAccessor to catch a NoSuchPropertyException, check the message, then re-throw it with the more specific method above. This fix would only be made for Symfony 6.
Additional Context
This issue is being moved from #46867 since it involves the form component specifically, rather than the framework respository.
The text was updated successfully, but these errors were encountered:
Symfony version(s) affected
4,5,6, possibly others
Description
Currently, if a form field does not have an equivalent setter or adder and does not use the ['mapped' => false] option, we get a NoSuchPropertyException that complains about a lack of setters or adders when submitting the form. (Later versions of Symfony use a slightly different message, but it's equally uninformative.)
(This is Symfony\Component\PropertyAccess\PropertyAccessor::getReadAccessInfo(), in the method's final else branch.)
That's fine, I guess, but it can be a little bit confusing. I suggest instead using a message like
Could not determine access type for property "title" in class "App\Entity\Post". Please either make the corresponding property public, add getters and setters, or set the form type's corresponding field to use a "mapped" value of false.
How to reproduce
Create a form field in a form type that doesn't have a setter or adder associated with it in the equivalent Doctrine entity (where the property should be private), and don't pass any options to the field. Then submit the form. You should get a nice NoSuchPropertyException talking about the missing methods, but it won't mention anything about how to solve the issue if you don't want to add those methods.
Possible Solution
I will modify the part of the
PropertyPathAccessor
to catch a NoSuchPropertyException, check the message, then re-throw it with the more specific method above. This fix would only be made for Symfony 6.Additional Context
This issue is being moved from #46867 since it involves the form component specifically, rather than the framework respository.
The text was updated successfully, but these errors were encountered: