Fix native lazy object change tracking#12434
Conversation
Native lazy objects may be registered as managed with an empty original-data snapshot while they are still uninitialized. When Doctrine later sets their remaining lazy properties, PHP can mark the object as initialized without refreshing UnitOfWork original data. Change-set computation then treats the empty snapshot as a partial load and skips all fields. Record original data when Doctrine initializes such objects through association wiring, and fall back to an update changeset if an initialized native lazy object still has an empty snapshot. Fixes doctrine#12403
9b88eb7 to
0a3f5b7
Compare
|
As this is an extremely low level and complex change, did you use AI for this change? Its fine if you do, but please be transparent about it. |
|
@beberlei Yes absolutly, I did use AI mainly to help me understand the core logic of the unit of work, write the tests and have a big picture of the changes that we needed to do in the unit of work. I should have make that clear sorry. After reviewing the changes, the tests looked quite good to me and are easy to understand. As for the changes in the unit of work, the main "fix" is here : The added functions are mainly written to re-use code logic. I'm very open to changes in this PR or even closing it. I did it in the first place because it's quite a important bug IMO for anyone using the new native lazy objects feature. |
|
We too have this issue when using native lazy objects, the UnitOfWork does not detect the ChangeSet and entities are not persisted. This PR appears to resolve the issue, but we are blocked from resolving the @beberlei Can this PR be progressed? |
|
Comming back on this issue, I found a way to workaround this issue by skipping totally native objects on this version, but if it was not clear enough, one to one relations represented in the tests I added in this PR shows the issue. I don't understand why we don't have news about this. My proposed fix may be low level and dangerous, but at least regression tests are here. Unless I'm missing something, this is a huge regression, no ? So I'm happy to discuss this, even though I'm personnaly ok with this issue since I found it and managed to deal with it by founding the hard way that it broke my projects. |
|
Did not have the time to look at this yet, sorry |
Fixes #12403
Native lazy objects may be registered as managed with an empty original-data snapshot while they are still uninitialized.
When Doctrine later sets their remaining lazy properties, PHP can mark the object as initialized without refreshing UnitOfWork original data. Change-set computation then treats the empty snapshot as a partial load and skips all fields.
Record original data when Doctrine initializes such objects through association wiring, and fall back to an update changeset if an initialized native lazy object still has an empty snapshot.
Added regression coverage for:
no original-data snapshot
was not persisted