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

DDC-3619: spl_object_hash collision #4444

Closed
doctrinebot opened this issue Mar 17, 2015 · 10 comments
Closed

DDC-3619: spl_object_hash collision #4444

doctrinebot opened this issue Mar 17, 2015 · 10 comments
Assignees
Labels
Milestone

Comments

@doctrinebot
Copy link

Jira issue originally created by user Akhristenko:

The code below demonstrate problem.

$user = $entityManager->find(User::class, $id); // get entity from db
$entityManager->remove($user); // remove user
$entityManager->persist($user); // cancel remove
unset($user);
/** at this moment spl_object_hash($user) is presented in the UoW, but the $user isn't presented in the identity map in UoW **/
$user2 = new User(); // spl*object_hash($user2) may be equal to spl_object*hash($user) because $user has no reference
$entityManager->persist($user2);
$entityManager->flush(); //$user2 will not be saved, because UoW think, that is already exists
@doctrinebot
Copy link
Author

Comment created by @Ocramius:

{quote}spl_object_hash($user2) may be equal to spl_object_hash($user) because $user has no reference{quote}

this seems wrong, since $user won't get garbage collected

@doctrinebot
Copy link
Author

Comment created by Akhristenko:

Why? The $user has no reference to it, so it may be collected.
I use SoftDeleteabale extension and faced with this problem.
My code is look like:

function delete($id) {
  $entity = $entityManager->find(Entity::class, $id);
  $entityManager->delete($entity); // the softdeleteable extension call persist($entity) and remove $entity from sheduledForDeletion in onFlush
  $entityManager->flush($entity);
} // after this function the UoW contains spl*object*hash($entity), but not contains $entity. After leave function $entity collected.
function createAnother() {
  $anotherEntity = new AnotherEntity();
  $entityManager->persist($anotherEntity);
  $entityManager->flush($anotherEntity); // there is a spl*object*hash collision and the entity is not saved
}
function main() {
  //...
  delete($id);
  //...
  createAnother();
}

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

[~Akhristenko] the UoW has an internal reference to $user, so it cannot be garbage collected

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

I suggest abstracting this problem into a test case in order to remove these doubts upfront.

@doctrinebot
Copy link
Author

Comment created by Akhristenko:

{quote}
Aleksandr Khristenko the UoW has an internal reference to $user, so it cannot be garbage collected
{quote}
Yes, but when we call remove($entity) this internal reference move from identityMap to entityDeletions array. And when we after that call persist($entity) this internal reference remove from entityDeletions array but NOT added to identityMap. So, after that UoW has not an internal reference to $user.

@doctrinebot
Copy link
Author

Comment created by Akhristenko:

I attached the test, which demonstrates that reference to entity from UoW is lost.

@doctrinebot
Copy link
Author

Comment created by nclavaud:

I am also using SoftDeleteable Doctrine extension (https://github.com/Atlantic18/DoctrineExtensions) and facing a similar issue.

My scenario is:

  • fetch 2 entities from db ;
  • soft-delete these 2 entities (then flush) ;
  • create 3 new entities and persist them (then flush).

Problem is: 1 of the 3 entities won't be persisted (same $oid than one of the soft-deleted ones).

I've created a PR here that solves my issue:
#1338

Does it make sense to you?

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1338] was closed:
#1338

@doctrinebot
Copy link
Author

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.4.8 milestone Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants