Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-182

Changing entity in preUpdate hook tramples existing changes

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      If the object is changed during the pre-update callback, this causes the previous changes to be discarded.

      Steps to reproduce:

      • Create entity with pre-update lifecycle callback
      • Change property A,
      • Call flush.
      • Change property B in pre-update callback

      Result is that changes to property A are discarded.

      The reason for that is that at the end of Doctrine\ORM\UnitOfWork::_computeEntityChanges() these two statements appear:

      $this->_entityChangeSets[$oid] = $changeSet;
      $this->_originalEntityData[$oid] = $actualData;
      

      However at the end of Doctrine\ORM\UnitOfWork::computeSingleEntityChangeSet(), which is called after the pre-update callbacks are called, the same thing happens:

      $this->_entityChangeSets[$oid] = $changeSet;
      $this->_originalEntityData[$oid] = $actualData;
      

      Because the original data is recorded as equal to the state of the object after the first call to _computeEntityChanges(), the call to computeSingleEntityChangeSet() does not detect the original set of changes, it only detects the changes made in the pre-update hooks. But at the same time, both methods completely overwrite the changeset buffer for the entity rather than merge it. The result is that the first changeset is completely discarded.

        Activity

        Hide
        Roman S. Borschel added a comment -

        Are you sure this is still a valid issue? See DDC-74. This sounds like the same thing.

        Show
        Roman S. Borschel added a comment - Are you sure this is still a valid issue? See DDC-74 . This sounds like the same thing.
        Hide
        Amir Abiri added a comment -

        You are right and I'm sorry. I only went over the list of outstanding issues to avoid double-reporting, didn't occur to me this might have been fixed already.

        Show
        Amir Abiri added a comment - You are right and I'm sorry. I only went over the list of outstanding issues to avoid double-reporting, didn't occur to me this might have been fixed already.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Amir Abiri
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: