Skip to content

Commit

Permalink
[GH-8231] Bugfix: Missed dirty check synchronization check. (#8392)
Browse files Browse the repository at this point in the history
When an entity with change tracking policy "deferred explicit" gets
removed, then persisted again, it is not schedulded for a dirty check
synchronization. This is not the case for entities that are persisted
and are already in the managed state.
  • Loading branch information
beberlei authored Dec 14, 2020
1 parent 277b53a commit 8b74964
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,10 @@ private function doPersist($entity, array &$visited)
$this->addToIdentityMap($entity);

$this->entityStates[$oid] = self::STATE_MANAGED;

if ($class->isChangeTrackingDeferredExplicit()) {
$this->scheduleForDirtyCheck($entity);
}
break;

case self::STATE_DETACHED:
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public function testClearScheduledForSynchronizationWhenCommitEmpty(): void

self::assertFalse($this->_em->getUnitOfWork()->isScheduledForDirtyCheck($entity));
}

/**
* @group GH-8231
*/
public function testPersistAfterRemoveSchedulesForSynchronization(): void
{
$entity = $this->_em->find(GH7629Entity::class, 1);

$this->_em->remove($entity);

$this->_em->persist($entity);

self::assertTrue($this->_em->getUnitOfWork()->isScheduledForDirtyCheck($entity));
}
}

/**
Expand Down

0 comments on commit 8b74964

Please sign in to comment.