After refresh my entity it is updated (doctrine do SQL UPDATE) #6879

Open
opened 2026-01-22 15:40:32 +01:00 by admin · 0 comments
Owner

Originally created by @man-htsts on GitHub (Nov 24, 2021).

Bug Report

Q A
BC Break no (not sure)
Version 2.10.2

Summary

When i call refresh() on my entity, it is become unchanged (fresh state from DB). But then i call flush(), doctrine execute UPDATE statements, like my entity is still dirty.

Current behavior

It is because in UOW the entity is still in entityUpdates array.
And more to this, then in recomputeSingleEntityChangeSet() in the end the $changeSet is empty array, and the if clause if ($changeSet) blocks doctrine to know that there is no real changes at the moment. And after it doctrine insert in DB old changes, that have been refreshed, but still stay in doctrine UOW $entityChangeSets cache.

How to reproduce

$book = $em->find(App\Entity\Book:class, 1);
$book->setValue('new');
$em->refresh($book);
$em->flush();

Expected behavior

After refresh() it should not update my entity in DB.
It can be done, IMHO, if on refresh remove in from $entityUpdates and or from $changeSet. Or by patching recomputeSingleEntityChangeSet() to make it save if changeSet become empty.

Originally created by @man-htsts on GitHub (Nov 24, 2021). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no (not sure) | Version | 2.10.2 #### Summary <!-- Provide a summary describing the problem you are experiencing. --> When i call refresh() on my entity, it is become unchanged (fresh state from DB). But then i call flush(), doctrine execute UPDATE statements, like my entity is still dirty. #### Current behavior <!-- What is the current (buggy) behavior? --> It is because in UOW the entity is still in entityUpdates array. And more to this, then in recomputeSingleEntityChangeSet() in the end the $changeSet is empty array, and the if clause `if ($changeSet)` blocks doctrine to know that there is no real changes at the moment. And after it doctrine insert in DB old changes, that have been refreshed, but still stay in doctrine UOW $entityChangeSets cache. #### How to reproduce <!-- Provide steps to reproduce the bug. If possible, also add a code snippet with relevant configuration, entity mappings, DQL etc. Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> ``` $book = $em->find(App\Entity\Book:class, 1); $book->setValue('new'); $em->refresh($book); $em->flush(); ``` #### Expected behavior <!-- What was the expected (correct) behavior? --> After refresh() it should not update my entity in DB. It can be done, IMHO, if on refresh remove in from $entityUpdates and or from $changeSet. Or by patching recomputeSingleEntityChangeSet() to make it save if changeSet become empty.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6879