DDC-3693: Notify change tracking policy breaks in the face of individual entity flushes #4536

Open
opened 2026-01-22 14:44:19 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Apr 15, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user napsi:

The notify change tracking policy breaks, if other entities are individually flushed between change and flush on a given notify-based entity.

The culprit seems to be that UnitOfWork.commit() resets its scheduledForSynchronization and entityChangeSets arrays (name(s) has changed since 2.2.2) - even when the commit is for a single entity, and the arrays hold other scheduled entities/changes.

An example:

use \net\jay\test\A;

$em = \Doctrine2::getEntityManager();

# persist and flush two instances of A
$a1 = new A(1, 'x');
$a2 = new A(2, 'y');
$em->persist($a1);
$em->persist($a2);
$em->flush();

# change both, but flush $a2 first, then do a general flush
$a1->setName('xx');
$a2->setName('yy');
$em->flush($a2);
$em->flush();

# $a1 entity should be changed, but isn't
$em->clear();
$a1 = $em->getRepository('net\jay\test\A')->find(1);
echo $a1->getName(); # = 'x' (should be 'xx')
namespace net\jay\test;

/****
 * @Entity
 * @ChangeTrackingPolicy("NOTIFY")
 */
class A implements \Doctrine\Common\NotifyPropertyChanged
{
    /*** @Id @Column(type="integer") **/
    private $id;

    /*** @Column(length=100) **/
    private $name;

    private $_changeListeners;

    public function **construct($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    public function addPropertyChangedListener(\Doctrine\Common\PropertyChangedListener $listener)
    {
        $this->_changeListeners[] = $listener;
    }

    private function _onPropertyChanged($propName, $oldValue, $newValue)
    {
        if ($this->_changeListeners)
        {
            foreach ($this->_changeListeners as $listener)
            {
                $listener->propertyChanged($this, $propName, $oldValue, $newValue);
            }
        }
    }

    public function getID()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->_onPropertyChanged('name', $this->name, $name);
        $this->name = $name;
    }
}
Originally created by @doctrinebot on GitHub (Apr 15, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user napsi: The notify change tracking policy breaks, if other entities are individually flushed between change and flush on a given notify-based entity. The culprit seems to be that UnitOfWork.commit() resets its scheduledForSynchronization and entityChangeSets arrays (name(s) has changed since 2.2.2) - even when the commit is for a single entity, and the arrays hold other scheduled entities/changes. An example: ``` use \net\jay\test\A; $em = \Doctrine2::getEntityManager(); # persist and flush two instances of A $a1 = new A(1, 'x'); $a2 = new A(2, 'y'); $em->persist($a1); $em->persist($a2); $em->flush(); # change both, but flush $a2 first, then do a general flush $a1->setName('xx'); $a2->setName('yy'); $em->flush($a2); $em->flush(); # $a1 entity should be changed, but isn't $em->clear(); $a1 = $em->getRepository('net\jay\test\A')->find(1); echo $a1->getName(); # = 'x' (should be 'xx') ``` ``` namespace net\jay\test; /**** * @Entity * @ChangeTrackingPolicy("NOTIFY") */ class A implements \Doctrine\Common\NotifyPropertyChanged { /*** @Id @Column(type="integer") **/ private $id; /*** @Column(length=100) **/ private $name; private $_changeListeners; public function **construct($id, $name) { $this->id = $id; $this->name = $name; } public function addPropertyChangedListener(\Doctrine\Common\PropertyChangedListener $listener) { $this->_changeListeners[] = $listener; } private function _onPropertyChanged($propName, $oldValue, $newValue) { if ($this->_changeListeners) { foreach ($this->_changeListeners as $listener) { $listener->propertyChanged($this, $propName, $oldValue, $newValue); } } } public function getID() { return $this->id; } public function getName() { return $this->name; } public function setName($name) { $this->_onPropertyChanged('name', $this->name, $name); $this->name = $name; } } ```
admin added the Bug label 2026-01-22 14:44:19 +01:00
Author
Owner

@ngandemer commented on GitHub (May 26, 2016):

Same issue :(

@ngandemer commented on GitHub (May 26, 2016): Same issue :(
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4536