Using a nested context causes awakeFromInsert to be called twice

Originator:krismarkel
Number:rdar://11185875 Date Originated:Apr 4, 2012
Status:Open Resolved:
Product:iPhone SDK Product Version:5.1
Classification:Serious Bug Reproducible:Always
 
Summary:

awakeFromInsert is called twice on a managed object subclass if the object is crated in a nested MOC and save is called on that MOC.

Steps to Reproduce:

1. Open the attached project (http://cl.ly/281T0B3L2s0R2g2K2L24), which overrides awakeFromInsert on the Event NSManagedObject subclass.
2. Build and run the project.
3. Add a new entry by pressing the "+" button.

Expected Results:

A single "awakeFromInsert called" message to appear in the debug output.

Actual Results:

2 messages appear in the debug output.

Regression:

Notes:

This appears to violate the documentation at http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdManagedObjects.html#//apple_ref/doc/uid/TP40003397-SW2 which says, "awakeFromInsert is invoked only once in the lifetime of an object—when it is first created"

What the "lifetime" of an object is here is not exactly clear, but the code sample at that link implies that you can use awakeFromInsert to set a creation date value on your MO. If the method is called twice, it's not clear which value should be used for the creation date.

This becomes more complicated if awakeFromInsert is used to create additional MOs and establish relationships. When the method is invoked the second time, it leads to extra MOs being created.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!