Core Data randomly reports updating an object, but it is unchanged
Core Data randomly reports updating an object, but it is unchanged
- Subject: Core Data randomly reports updating an object, but it is unchanged
- From: Jerry Krinock <email@hidden>
- Date: Mon, 02 Sep 2013 01:34:06 -0700
I launchd my Core Data document-based app 24 times. Each time, it opened the same document. 11 times, it worked fine. 13 times, it immediately set -isDocumentEdited to YES. This causes a problem in my app (long explanation omitted). In any case, it should not happen.
I overrode -updateChangeCount: and put a breakpoint in it. The call stack [1] is interesting, but does not provide any clues that I can see.
Since I'm observing NSManagedObjectContextObjectsDidChangeNotification, I set a breakpoint in the method observing this notification. A notification is received before -updateChangeCount: runs. Aha. This document contains about a dozen objects of its "main" entity. At the breakpoint, the notification's info lists a single one of these objects, always the same one, in NSUpdatedObjectsKey. But this object's -changedValues is an empty dictionary. Also, I logged the -description of this object (1) in -readFromURL:ofType:error: and (2) in my observer method. Comparing the two logs, all attributes are the same. The only difference is that in case (1) the object's 'children' relationship is a fault, and in case (2) it is an empty set. That is unsurprising.
Summary: 54% of the time, Core Data reports that it is updating this object after loading the store, but there is no change in the object, as far as I can see.
What would you do next?
The only thing I can think of is to say it's an inexplicable bug and patch around it. Yuck. Maybe override -updateChangeCount: and perform some verification before invoking super. I have a deep hash available and could put that in metadata. But this is getting dangerously close to the Lion Auto Save magic which is so easy to screw up; I'd rather not go there.
Thanks,
Jerry Krinock
[1] Call Stack
Thread 1, Queue : com.apple.main-thread
#0 -[MyDocument updateChangeCount:] at MyDocument.m:508
#1 __block_global_226 ()
#2 -[NSDocument _checkAutosavingThenContinue:] ()
#3 __52-[NSDocument _checkAutosavingThenUpdateChangeCount:]_block_invoke_0 ()
#4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#5 __CFRunLoopDoBlocks ()
#6 __CFRunLoopRun ()
#7 CFRunLoopRunSpecific ()
#8 RunCurrentEventLoopInMode ()
#9 ReceiveNextEventCommon ()
#10 BlockUntilNextEventMatchingListInMode ()
#11 _DPSNextEvent ()
#12 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#13 -[NSApplication run] ()
#14 NSApplicationMain ()
#15 main at /Users/jk/Documents/Programming/Projects/BkmkMgrs/Bkmx-Main.m:63
#16 start ()
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden