(Temp Fix available) Conflict with spl_object_hash on merge of to-many association when not mirrored on owning side #5337

Open
opened 2026-01-22 15:04:58 +01:00 by admin · 0 comments
Owner

Originally created by @Goatfried on GitHub (Dec 5, 2016).

Related to the lately merged #5689, It seems like I stumbled on an edge case where undesired conflicts where introduced.

I've an object order with many-to-one relations to parcels and items.
Both many-to-one relations are set-up with cascade-merge, while the owning sides are not set-up for cascade-merge. In the merge operation, new items are persisted as well.

If the owning side is not setup for cascade-merge, proxies are generated for the owning side on mergeEntityStateIntoManagedCopy and later replaced with the correct order object. These proxies are registered as managed, but never deleted.
Since the reference is thrown away immediately after merge, this leaks a spl_object_hash resulting in a collision.

This results in undesired side effects like inserting wrong ids on flush into the database.

The problem can be solved by defining the owning side as cascade-merge as well.

I'll provide a test for it later this week.

I'd like to contribute with a fix as well. I think, we could just update the state of the parent entity prior to cascadeMerge. I haven't found yet, where it's done currently.

With kind regards

Originally created by @Goatfried on GitHub (Dec 5, 2016). Related to the lately merged #5689, It seems like I stumbled on an edge case where undesired conflicts where introduced. I've an object order with many-to-one relations to parcels and items. Both many-to-one relations are set-up with cascade-merge, while the owning sides are not set-up for cascade-merge. In the merge operation, new items are persisted as well. If the owning side is not setup for cascade-merge, proxies are generated for the owning side on _mergeEntityStateIntoManagedCopy_ and later replaced with the correct order object. These proxies are registered as managed, but never deleted. Since the reference is thrown away immediately after merge, this leaks a spl_object_hash resulting in a collision. This results in undesired side effects like inserting wrong ids on flush into the database. The problem can be solved by defining the owning side as cascade-merge as well. I'll provide a test for it later this week. I'd like to contribute with a fix as well. I think, we could just update the state of the parent entity prior to cascadeMerge. I haven't found yet, where it's done currently. With kind regards
admin added the BugMissing Tests labels 2026-01-22 15:04:58 +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#5337