Skip to content
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

PropertyAccessor::getReadAccessInfo() throws exception that could be more specific #47386

Closed
patrickmaynard opened this issue Aug 25, 2022 · 0 comments

Comments

@patrickmaynard
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants