symfony: ValidatorException on Doctrine Proxy (Auto Validation Mapping?)

Symfony version(s) affected: 4.3 (Beta2 & RC1)

Description
Handling a request with a form that has an assigned Entity seems to wrongly trigger a ValidatorException.

How to reproduce My apologies for the missing reproducer - I’m having issues creating it. since 4.3.0-RC1 is affected I thought sharing even without one could help.

        $entityManager = $this->getDoctrine()->getManager();
        $person = $entityManager->getRepository(Person::class)->findOneBy(['id' => $id]);

        $form = $this->createForm(PersonType::class, $person);
        $form->handleRequest($request);

triggers

ValidatorException: Property "xyz" does not exist in class "Proxies\__CG__\App\Entity\Person"

in PropertyMetadata.php#L39-L41

The stacktrace is here: https://gist.github.com/fabstei/ee254c7945ebc79fd3fed75cf4de82db

Possible Solution
None so far. After uncommenting PropertyMetadata.php#L39-L41 everything works as expected, but it’s obviously not a solution.

Additional context

  • Mac OS Mojave 10.14.5
  • PHP 7.3.5

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 28 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@fabstei @MortalFlesh I have the same issue with embedded entities in a Symfony 4.3 migration

Unfortunately, using auto_mapping: {} doesn’t seem to help, DoctrineLoader is still called and the exception is thrown

The auto_mapper is always being registered by the doctrine-bundle, not sure how the auto_mapping param affects the registration: https://github.com/doctrine/DoctrineBundle/blob/master/DependencyInjection/DoctrineExtension.php#L811

EDIT: this works for me: auto_mapping: {'App\\': {}}

@guillaumesmo,

Thanks that seems to have worked for me;

framework.yaml

framework: validation: auto_mapping: {'App\\': {}}

I’m also seeing this error in Symfony 4.3.0. The property it’s complaining about is definitely in the entity. The property is defined as ‘@ORM\Column(type=“string”, length=100, nullable=true, unique=true)’

Same as above, settings the auto_mapping property does not resolve this. I’m also seeing a similar issue with inherited entities i.e. I have an entity class extending another - it’s unable to access properties of the base class.

Same for me, recently upgraded to 4.3.0, form with a EntityType, for now on, the properties of these entity must be public to avoid this exception?!?

@xabbuh that fixed the problem indeed, no need to the auto_mapping param anymore

Thank you

Can you check if #31836 finally solves this issue?

@pulsesalessolutions This works for me also!

#31749 is a first steps which at least ensures that auto mapping is not enabled by default. Though that doesn’t fix the core issue with Doctrine proxies.

It happens without enabling auto_mapping. For my project it’s been a straight switch of 4.2.* to 4.3.* in composer.json; only other changes are to clean up deprecations with the Workflow component.

Did you enable the new auto_mapping feature (see #27735) or does it also happen without doing so?