DDC-1835: Cloning PersistentCollection affects internal collection of clone source #2316

Closed
opened 2026-01-22 13:48:09 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (May 24, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user k-fish:

When a PersistentCollection (PC) is loaded and is cloned before it is initialized, anything that is already in that collection will be duplicated if the collection is initialized after it has been marked dirty. The cause is a too late clone operation on the internal (Array)Collection (AC) in the PC.

PC is loaded, but not initialized. The internal AC is empty.

PC is cloned. PC' calls initialize() in **clone()

PC' fills AC (as that has not been cloned yet)

PC' clones AC

As a result the AC in PC now contains elements, but PC still is uninitialized. If PC is afterwards initialized and dirty, the elements already in AC will be considered new and added again to the AC.

The effect will be constraint violations in join tables due to duplicate entries.

The clone method causing this has been introduced with commit 647bd2b2f295d2cbe7d0ee67f21be8a48bae3db5 on February 17th.

Originally created by @doctrinebot on GitHub (May 24, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user k-fish: When a PersistentCollection (PC) is loaded and is cloned before it is initialized, anything that is already in that collection will be duplicated if the collection is initialized after it has been marked dirty. The cause is a too late clone operation on the internal (Array)Collection (AC) in the PC. # PC is loaded, but not initialized. The internal AC is empty. # PC is cloned. PC' calls initialize() in **clone() # PC' fills AC (as that has not been cloned yet) # PC' clones AC As a result the AC in PC now contains elements, but PC still is uninitialized. If PC is afterwards initialized and dirty, the elements already in AC will be considered new and added again to the AC. The effect will be constraint violations in join tables due to duplicate entries. The clone method causing this has been introduced with commit [647bd2b2f295d2cbe7d0ee67f21be8a48bae3db5](https://github.com/doctrine/doctrine2/commit/647bd2b2f295d2cbe7d0ee67f21be8a48bae3db5) on February 17th.
admin added the Bug label 2026-01-22 13:48:09 +01:00
admin closed this issue 2026-01-22 13:48:09 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 24, 2012):

Comment created by k-fish:

Test and fix: https://github.com/doctrine/doctrine2/pull/356

@doctrinebot commented on GitHub (May 24, 2012): Comment created by k-fish: Test and fix: https://github.com/doctrine/doctrine2/pull/356
Author
Owner

@doctrinebot commented on GitHub (May 27, 2012):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 27, 2012): 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#2316