Skip to content

[DoctrineBridge] DC break with Doctrine ODM integration #60921

Open
@pepeh

Description

@pepeh

Symfony version(s) affected

6.4.20

Description

The following commit introduced a breaking change for Doctrine ODM integration:
symfony/doctrine-bridge@7205dbc

The problematic code is:

if (property_exists(OrmClassMetadata::class, 'propertyAccessors')) {
    $fieldValue = $class->propertyAccessors[$fieldName]->getValue($entity);
} else {
    $fieldValue = $class->reflFields[$fieldName]->getValue($entity);
}

The issue arises because the check only verifies whether the propertyAccessors property exists on the OrmClassMetadata class, but $class is actually an instance of Doctrine\ODM\MongoDB\Mapping\ClassMetadata, not Doctrine\ORM\Mapping\ClassMetadata when both ODM and ORM are installed on the same project.

Doctrine ODM does not define the propertyAccessors property, so this results in an error when the bridge tries to access a non-existent property.

How to reproduce

Install the latest ODM and ORM bundles in the same project, and then the Unique validator

<?php
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;

#[Document]
#[Unique(fields: ['name'])]
class User
{
    #[Field]
    private string $name;
    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): void
    {
        $this->name = $name;
    }
}

Possible Solution

Ensure that the metadata class being inspected is an instance of Doctrine\ORM\Mapping\ClassMetadata (or similar), not just that the OrmClassMetadata::class defines the property. For example:

if ($class instanceof \Doctrine\ORM\Mapping\ClassMetadata && property_exists($class, 'propertyAccessors')) {
   ...
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions