DDC-3297: Refreshing and locking entities ignores deleted records #4079

Open
opened 2026-01-22 14:34:44 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 7, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user darkangel:

If you refresh or lock an entity that has been deleted elsewhere, no exception is thrown, so it appears as if the record still exists.

Example:

    $blogId = 1;

    $em = (get em from somewhere);

    $blog = $em->find('App*Model*Blog', $blogId);

    var_dump($blog->getTitle());

    // This could be part of a separate request or transaction.
    $em->getConnection()->exec(sprintf('DELETE FROM blogs WHERE id = %d', $blogId));

    $stmt = $em->getConnection()->query(sprintf('SELECT * FROM blogs b WHERE b.id = %d', $blogId));

    var_dump($stmt->rowCount() === 0 ? 'DELETED' : 'NOT DELETED');

    //$em->beginTransaction();

    //$em->lock($blog, LockMode::PESSIMISTIC_WRITE);

    //$em->commit();

    $em->refresh($blog);

    var_dump($blog->getTitle());
Originally created by @doctrinebot on GitHub (Sep 7, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user darkangel: If you refresh or lock an entity that has been deleted elsewhere, no exception is thrown, so it appears as if the record still exists. Example: ``` $blogId = 1; $em = (get em from somewhere); $blog = $em->find('App*Model*Blog', $blogId); var_dump($blog->getTitle()); // This could be part of a separate request or transaction. $em->getConnection()->exec(sprintf('DELETE FROM blogs WHERE id = %d', $blogId)); $stmt = $em->getConnection()->query(sprintf('SELECT * FROM blogs b WHERE b.id = %d', $blogId)); var_dump($stmt->rowCount() === 0 ? 'DELETED' : 'NOT DELETED'); //$em->beginTransaction(); //$em->lock($blog, LockMode::PESSIMISTIC_WRITE); //$em->commit(); $em->refresh($blog); var_dump($blog->getTitle()); ```
admin added the Bug label 2026-01-22 14:34:44 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4079