Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading an entity that have been removed will create a new entity. #9463

Closed
mpoiriert opened this issue Feb 1, 2022 · 1 comment
Closed

Comments

@mpoiriert
Copy link

Bug Report

Q A
BC Break yes
Version 2.11.1

Summary

When remove en entity, before flush, if we fetch the entity again it will return a new object breaking the "unique instance pooling". Checking the state of this entity will be managed, checking directly if the entity is schedule for removing will return false.

I presume it will be consider a breaking change but fixing this seem to result in the expected behaviour.
The issue is related to the code removing the object from the identity map when the UnitOfWork::remove is call (via a chain of internal call).

Current behavior

Fetching an an entity schedule for removal will return a new object instance.

How to reproduce

// This is a simplified version of a more complex flow

$id = 1;

$object1 = $em->find('ObjectClass', $id);
$em->remove($object1);

$object2 = $em->find('ObjectClass', $id);

echo $em->getUniqueOfWork()->isScheduledForDelete($object1) ? 'yes' : 'no'; // yes

echo $em->getUniqueOfWork()->isScheduledForDelete($object2) ? 'yes' : 'no'; // no

echo $object1 === $object2 ? 'yes' : 'no'; // no

echo $object1->getId() === $object2->getId() ? 'yes' : 'no'; // yes

Expected behavior

$id = 1;

$object1 = $em->find('ObjectClass', $id);
$entityManager->remove($object1);

$object2 = $em->find('ObjectClass', $id);

echo $em->getUniqueOfWork()->isScheduledForDelete($object1) ? 'yes' : 'no'; // yes

echo $em->getUniqueOfWork()->isScheduledForDelete($object2) ? 'yes' : 'no'; // yes

echo $object1 === $object2 ? 'yes' : 'no'; // yes

echo $object1->getId() === $object2->getId() ? 'yes' : 'no'; // yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants