[DDC-1835] Cloning PersistentCollection affects internal collection of clone source Created: 24/May/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2
Fix Version/s: 2.1.7, 2.2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Karsten Dambekalns Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

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.

  1. PC is loaded, but not initialized. The internal AC is empty.
  2. PC is cloned. PC' calls initialize() in __clone()
  3. PC' fills AC (as that has not been cloned yet)
  4. 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.



 Comments   
Comment by Karsten Dambekalns [ 24/May/12 ]

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

Generated at Fri Dec 19 22:47:10 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.