DDC-3981: [GH-1546] Fix proxy erased by hydratation #4858

Closed
opened 2026-01-22 14:50:36 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 6, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of jderusse:

Url: https://github.com/doctrine/doctrine2/pull/1546

Message:

This PR fixe a edge case when hydrating an existing object which already has a proxy to diff��rente entity.

Imagine the entity

/*** @ORM\Entity() **/
class User
{
    //...

    /*** @ORM\ManyToOne(targetEntity="Address", fetch="EAGER") **/
    private $address;

    //...
}

/*** @ORM\Entity() **/
class Address
{
}

When a instance of User has an address created with a Proxy, then, the hydratation of an other instance of the same User will replace the content of the field address in this instance.

Such situation append with a PUT call with the DunglasApiBundle and the validator UniqueEntity from Symfony which trigger a $repository->find on the object.

  • First the entity is loaded from the entityManager (which store the reference in the identityMap of the uow
  • Then the serializer overrwrite the entity, and may create reference for the related properties
  • Then the object is validated before flushing which trigger the UniqueEntityValidator

How to reproduce:

$user = $repository->find($id);
var_dump($user->getAddress()->getId());
// 1337

$user->setAddress($em->getReference('Address', 42));
var_dump($user->getAddress()->getId());
// 42

$somethingElse = $repository->find($id);
var_dump($user->getAddress()->getId());
// 1337
Originally created by @doctrinebot on GitHub (Nov 6, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of jderusse: Url: https://github.com/doctrine/doctrine2/pull/1546 Message: This PR fixe a edge case when hydrating an existing object which already has a proxy to diff��rente entity. Imagine the entity ``` /*** @ORM\Entity() **/ class User { //... /*** @ORM\ManyToOne(targetEntity="Address", fetch="EAGER") **/ private $address; //... } /*** @ORM\Entity() **/ class Address { } ``` When a instance of `User` has an address created with a `Proxy`, then, the hydratation of an other instance of the same `User` will replace the content of the field `address` in this instance. Such situation append with a PUT call with the [DunglasApiBundle](https://github.com/dunglas/DunglasApiBundle) and the validator [UniqueEntity](https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php) from Symfony which trigger a `$repository->find` on the object. - First the entity is loaded from the entityManager (which store the reference in the `identityMap` of the `uow` - Then the serializer overrwrite the entity, and may create reference for the related properties - Then the object is validated before flushing which trigger the UniqueEntityValidator How to reproduce: ``` $user = $repository->find($id); var_dump($user->getAddress()->getId()); // 1337 $user->setAddress($em->getReference('Address', 42)); var_dump($user->getAddress()->getId()); // 42 $somethingElse = $repository->find($id); var_dump($user->getAddress()->getId()); // 1337 ```
admin added the Bug label 2026-01-22 14:50:36 +01:00
admin closed this issue 2026-01-22 14:50:36 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1546] was labeled:
https://github.com/doctrine/doctrine2/pull/1546

@doctrinebot commented on GitHub (Nov 6, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1546] was labeled: https://github.com/doctrine/doctrine2/pull/1546
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1546] was labeled:
https://github.com/doctrine/doctrine2/pull/1546

@doctrinebot commented on GitHub (Nov 7, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1546] was labeled: https://github.com/doctrine/doctrine2/pull/1546
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1546] was unlabeled:
https://github.com/doctrine/doctrine2/pull/1546

@doctrinebot commented on GitHub (Nov 7, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1546] was unlabeled: https://github.com/doctrine/doctrine2/pull/1546
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1546] was assigned:
https://github.com/doctrine/doctrine2/pull/1546

@doctrinebot commented on GitHub (Nov 7, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1546] was assigned: https://github.com/doctrine/doctrine2/pull/1546
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1546] was labeled:
https://github.com/doctrine/doctrine2/pull/1546

@doctrinebot commented on GitHub (Nov 7, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1546] was labeled: https://github.com/doctrine/doctrine2/pull/1546
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4858