I just updated from 1.15.2 to 1.16.2 and Symfony keeped crashing on this exception:
[InvalidArgumentException]
The "AppBundle\Entity\ThirdParty" class must define a "__toString()" method because it is used as the "thirdParties
" field in the "show" view of the "User" entity.
But the thirdParties fiels is not used whatsoever in EasyAdmin config files. I implemented __toString() methods returning an empty string as a hotfix and it works now, but could you fix this, please?
Thank you.
But the thirdParties fiels is not used whatsoever in EasyAdmin config files.
Are you sure? Maybe you let easyadmin generate the fields to use for the show or list views? Because it seems we explicitly inspect only configured fields for a given action.
I even tried to disable the show view which is supposed to do the problem:
User:
class: AppBundle\Entity\User
disabled_actions: ['show']
And this is in the list section for the User entity:
list:
fields: ['id', 'username', 'email', 'lastLogin', 'enabled']
actions:
- { name: 'edit', icon: 'pencil', label: '' }
- { name: 'delete', icon: 'close', label: '' }
@ikvasnica if you don't define which fields to display in the show action, EasyAdmin selects some fields automatically. One of those fields seems to be a Doctrine association ... and those associations require to define the __toString() to avoid PHP errors ... that's why you see the error message (that we introduced in recent versions of the bundle).
In any case, your issue made me realize that we have an issue here ... if the show action is disabled, we shouldn't check this. So I'm going to fix this in a pull request. Thanks.
Closing it as fixed by #1407.
I've got a similar error message as of 1.16.2 , however my entity has a __toString method. If I ervert to 1.16.1 it works as expected.
Thank you for the fix, @javiereguiluz :)
@COil which one of the two related error messages do you see? The first one is about Doctrine associations and the second one about autocomplete fields.
It's strange that this fails because the check is trivial:
if (!method_exists($fieldConfig['targetEntity'], '__toString')) { ... }
@javiereguiluz Humm, let me check if I still have the problem.
Hi @javiereguiluz , I confirm the bug, I have this bug with 1.16.2 , with 1.16.1 it works as expected. It can't find the __toString method even it is in the entity, quiet weird !
@COil at the end I reverted this feature. If you upgrade to the new 1.16.3 version, this error should be gone. Thanks!