DDC-534: UnitOfWork propertyChanged does nto check if the notified model property is one being persisted #663

Closed
opened 2026-01-22 12:46:02 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 21, 2010).

Jira issue originally created by user disago:

When a Model implements NotifyPropertyChanged interface it may use the registered listeners for other purposes beyond the ORM and when the property being notified is not managed by Doctrine it will rise an undefined index propertyName PHP warning when trying to execute the updates.

Proposed solution:

Change UnitOfWork::propertyChanged to check whether the notified property is part of entitiy's metadata (right now it only checks if the property has association mappings and if not it just adds the entity to $this->_entityUpdates) :

public function propertyChanged($entity, $propertyName, $oldValue, $newValue) {
/** .. code ... **/ 
        } else {
            $this->_entityUpdates[$oid] = $entity;
        }
}

to

public function propertyChanged($entity, $propertyName, $oldValue, $newValue) {
/** .. code ... **/ 
        } elseif ($class->hasField($propertyName)) {

            $this->_entityUpdates[$oid] = $entity;
        }
}

NOTE: If the propertyChanged is modified this way the entity will not fire lifecycle events if only that property is modified. Maybe a better solution is to fire the lifecycle events (if any) but if the property is not being persisted then do not try to update it.

Originally created by @doctrinebot on GitHub (Apr 21, 2010). Jira issue originally created by user disago: When a Model implements _NotifyPropertyChanged_ interface it may use the registered listeners for other purposes beyond the ORM and when the property being notified is not managed by Doctrine it will rise an undefined index _propertyName_ PHP warning when trying to execute the updates. Proposed solution: Change _UnitOfWork::propertyChanged_ to check whether the notified property is part of entitiy's metadata (right now it only checks if the property has association mappings and if not it just adds the entity to $this->_entityUpdates) : ``` public function propertyChanged($entity, $propertyName, $oldValue, $newValue) { /** .. code ... **/ } else { $this->_entityUpdates[$oid] = $entity; } } ``` to ``` public function propertyChanged($entity, $propertyName, $oldValue, $newValue) { /** .. code ... **/ } elseif ($class->hasField($propertyName)) { $this->_entityUpdates[$oid] = $entity; } } ``` **NOTE:** If the propertyChanged is modified this way the entity will not fire lifecycle events if only that property is modified. Maybe a better solution is to fire the lifecycle events (if any) but if the property is not being persisted then do not try to update it.
admin added the Bug label 2026-01-22 12:46:02 +01:00
admin closed this issue 2026-01-22 12:46:04 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 1, 2010):

Comment created by romanb:

That lifecycle events would not fire would be correct. Doctrine should not care about non-persistent state. It does not do that with the other change-tracking policies, too.

Thanks for the report! I will fix that soon.

@doctrinebot commented on GitHub (May 1, 2010): Comment created by romanb: That lifecycle events would not fire would be correct. Doctrine should not care about non-persistent state. It does not do that with the other change-tracking policies, too. Thanks for the report! I will fix that soon.
Author
Owner

@doctrinebot commented on GitHub (May 1, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 1, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#663