BasicEntityPersister::getValues does not work when entity metadata is not loaded before #6482

Closed
opened 2026-01-22 15:33:54 +01:00 by admin · 2 comments
Owner

Originally created by @ghost on GitHub (Jun 8, 2020).

Bug Report

Detailed info is here https://github.com/theastar/metadata-bug-reproducer, a summary is below.

Q A
BC Break no
Version 2.7.3

Summary

There is a mapped superclass entity Person and its derived entity PersonInmate.

Calling \Doctrine\ORM\EntityRepository::findOneBy with ['person' => new PersonInmate()] if metadata for PersonInmate is not yet loaded results in a object-to-int cast and a notice "Object of class App\Entity\PersonInmate could not be converted to int""

Current behavior

The problem is that findOneBy depends on the context of the application. If the metadata for an entity is not loaded before findOneBy is called, it will not work.

How to reproduce

See README in https://github.com/theastar/metadata-bug-reproducer.

Expected behavior

\Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getValues (or somewhere in the call chain) should load metadata if it's not yet loaded, like this:

# \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getValues
# (...)
        $classMetadataFactory = $this->em->getMetadataFactory();
        $className = ClassUtils::getClass($value);
        $hasMetadataFor = $classMetadataFactory->hasMetadataFor($className);
        if (!$hasMetadataFor) {
            $classMetadataFactory->getMetadataFor($className);
        }
        if (is_object($value) && $classMetadataFactory->hasMetadataFor($className)) {
Originally created by @ghost on GitHub (Jun 8, 2020). ### Bug Report Detailed info is here https://github.com/theastar/metadata-bug-reproducer, a summary is below. | Q | A |------------ | ------ | BC Break | no | Version | 2.7.3 #### Summary There is a mapped superclass entity `Person` and its derived entity `PersonInmate`. Calling `\Doctrine\ORM\EntityRepository::findOneBy` with `['person' => new PersonInmate()]` if metadata for `PersonInmate` is not yet loaded results in a object-to-int cast and a notice "Object of class App\Entity\PersonInmate could not be converted to int"" #### Current behavior The problem is that findOneBy depends on the context of the application. If the metadata for an entity is not loaded before findOneBy is called, it will not work. #### How to reproduce See README in https://github.com/theastar/metadata-bug-reproducer. #### Expected behavior `\Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getValues` (or somewhere in the call chain) should load metadata if it's not yet loaded, like this: ``` # \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getValues # (...) $classMetadataFactory = $this->em->getMetadataFactory(); $className = ClassUtils::getClass($value); $hasMetadataFor = $classMetadataFactory->hasMetadataFor($className); if (!$hasMetadataFor) { $classMetadataFactory->getMetadataFor($className); } if (is_object($value) && $classMetadataFactory->hasMetadataFor($className)) { ```
admin added the Hacktoberfest label 2026-01-22 15:33:54 +01:00
admin closed this issue 2026-01-22 15:33:54 +01:00
Author
Owner

@beberlei commented on GitHub (Sep 25, 2020):

There behavior here should probably be aligned with AbstractQuery::processParameterValue, which is essentially the related logic for processing parameters in DQL/Native queries.

@beberlei commented on GitHub (Sep 25, 2020): There behavior here should probably be aligned with `AbstractQuery::processParameterValue`, which is essentially the related logic for processing parameters in DQL/Native queries.
Author
Owner

@beberlei commented on GitHub (Sep 25, 2020):

Duplicate of #7512

@beberlei commented on GitHub (Sep 25, 2020): Duplicate of #7512
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6482