mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Generated columns with insertable/updatable=false cause false positive change detection #7525
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SherinBloemendaal on GitHub (Jun 23, 2025).
Bug Report
Summary
Doctrine's UnitOfWork incorrectly detects changes for database-generated columns marked with
insertable: falseandupdatable: false. This causes entities to be scheduled for update even though no actual changes have occurred, which can trigger unwanted events and break change tracking logic.Current behavior
When an entity has database-generated columns (e.g.,
GENERATED ALWAYS AScolumns) marked with bothinsertable: falseandupdatable: false, the UnitOfWork still includes these fields in change detection. This results in:$entityUpdatesgetEntityChangeSet()returning phantom changes like['generatedField' => [null, DateTimeImmutable]]isScheduledForUpdate()returningtruewhen only generated fields have changedpreUpdateevents being triggered unnecessarilyExpected behavior
insertable: falseshould not appear in changesets for new entities during INSERT operationsupdatable: falseshould not appear in changesets for existing entities during UPDATE operationsHow to reproduce
The issue occurs in
UnitOfWork::computeChangeSet()andUnitOfWork::recomputeSingleEntityChangeSet()which don't check thenotInsertableandnotUpdatablefield mapping properties during change detection.@SherinBloemendaal commented on GitHub (Jun 23, 2025):
I seems to only occur for DateTime types (after hydration, a new DateTime object is created). I've created a pull request with reproducer test + possible fix.