[PR #7318] Original entity data is missing id when computing change set for already managed entity #10422

Closed
opened 2026-01-22 16:07:29 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/7318

State: closed
Merged: No


I'm targeting 2.6 branch because it's a bugfix.

The bug happens when you persist again a managed entity.

  • if entity has auto-generated id, original entity data will be missing id after computing change set.
  • if entity owns a collection, that collection will be also missing

As you can see from the test case - steps to reproduce are pretty simple.

For id:

  1. Have an entity with auto-generated id. This entity should be previously persisted (has an id, is managed).
  2. Change any mapped property in the object.
  3. Persist and commit changed entity or call UnitOfWork::computeSingleEntityChangeSet() or UnitOfWork::recomputeSingleEntityChangeSet() directly.
  4. Result: original entity data for that object contains object data including the changes from step 2, but is missing the id.

For collections:

  1. Have an entity A which contains collection of B.
  2. Persist A, ArrayCollection becomes PersistentCollection. Original entity data is correct.
  3. Change any mapped property in A object.
  4. Persist it again.
  5. Collection is missing from original entity data.

Id is missing because when populating $actualData array, auto-generated id value is ignored. It makes sense, because user shouldn't be able to set it manually.
I made a simple fix, which preserves id contained in original entity data when overwriting original data with $actualData.

**Original Pull Request:** https://github.com/doctrine/orm/pull/7318 **State:** closed **Merged:** No --- I'm targeting 2.6 branch because it's a bugfix. The bug happens when you persist again a managed entity. - if entity has auto-generated id, original entity data will be missing id after computing change set. - if entity owns a collection, that collection will be also missing As you can see from the test case - steps to reproduce are pretty simple. **For id:** 1. Have an entity with auto-generated id. This entity should be previously persisted (has an id, is managed). 2. Change any mapped property in the object. 3. Persist and commit changed entity or call `UnitOfWork::computeSingleEntityChangeSet()` or `UnitOfWork::recomputeSingleEntityChangeSet()` directly. 4. Result: original entity data for that object contains object data including the changes from step 2, but is missing the id. **For collections:** 1. Have an entity A which contains collection of B. 2. Persist A, ArrayCollection becomes PersistentCollection. Original entity data is correct. 3. Change any mapped property in A object. 4. Persist it again. 5. Collection is missing from original entity data. Id is missing because when populating `$actualData` array, auto-generated id value is ignored. It makes sense, because user shouldn't be able to set it manually. I made a simple fix, which preserves id contained in original entity data when overwriting original data with `$actualData`.
admin added the pull-request label 2026-01-22 16:07:29 +01:00
admin closed this issue 2026-01-22 16:07:29 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#10422