Skip to content

Bug: UnitOfWork try to set null to a read-only id column after remove #9538

@viniciusss

Description

@viniciusss

Bug Report

Q A
BC Break no
Version 2.11.1
PHP Version 8.1.1

Summary

I have a entity with a read-only id property, and when a try to remove the entry a receive a LogicException. Attempting to change readonly property App\Entity\Supplier::$id.

Current behavior

The UnitOfWork always try to set the id of entity to null when it' executes the executeDeletions method.

//$this->entityStates[$oid] = self::STATE_NEW;
if (! $class->isIdentifierNatural()) {
$class->reflFields[$class->identifier[0]]->setValue($entity, null);

How to reproduce

#[ORM\Entity]
class Supplier
{
    #[ORM\Id]
    #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    public readonly int $id;

    public function __construct(
        #[ORM\Column(nullable: false)]
        public readonly string $name,
    ) {}
}
$entityManager->find(Supplier::class, 1);
$entityManager->remove($entity);
$entityManager->flush($entity);

Expected behavior

Delete the entry from database, but i dont know what's the expected behavior to the orm internals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions