Re: Core Data merge and "statement is still active" error?
Re: Core Data merge and "statement is still active" error?
- Subject: Re: Core Data merge and "statement is still active" error?
- From: Ben Trumbull <email@hidden>
- Date: Thu, 5 Jun 2008 17:37:34 -0400
On Jun 3, 2008, at 8:15 PM, Michael Link wrote:
Is there a reason you're not using Core Data's -
mergeChangesFromContextDidSaveNotification: ?
If the object is modified (inserted, update, or deleted), you
should pass in YES to -refreshObject:mergeChanges:
Actually I am using mergeChangesFromContextDidSaveNotification:, I
am calling refreshObject:mergeChanges: with NO on the
NSUpdatedObjectsKey objects just before as this avoids the problem
of Bug 5937572.
You shouldn't call -refreshObject:mergeChanges:NO on an object with
changes (passing YES is okay). The reason for this is if the object
is deleted or inserted, nuking that state is just plain weird. The
graph of objects will not behave they way you would wish. A nuked
inserted object is stuck in limbo, and a nuked deleted object can be a
stale pointer for any of the objects related to it across inverse
relationships. Nuking an updated object also has a high probability
of corrupting the relationship state for other objects with
relationships to it.
Since the objects on the main thread aren't supposed to have changes,
skipping the changed ones shouldn't be a burden.
At this point we can now look at ObjectA (which is the same as
ObjectB except it is owned by the main thread's MOC) which will show
that it has 10 friends. It should have 20 but the merge has deleted
the 10 friends that were just inserted on the background thread, but
just for ObjectA. Looking at those 10 objects that were deleted on
the main thread you will find that they are still friends with
ObjectA. This leaves the object graph in an inconsistent state.
The object on the main thread seems to think it has local changes to
the "friends" relationship and during the merge this is trumping the
changes you've just made in the other context. I'm still
investigating the issue with the new example.
I have an Xcode project that can show both bug 5937572, where the
object graph is left in an inconsistent state after a merge and bug
5982319, where the "statement is still active" exception occurs
during a merge. The project is already attached to bug 5982319
(Bug-1.zip) and is setup to show the behavior regarding that issue.
To see the other issue comment out lines 154-189 and uncomment lines
193-237 in MyDocument.m
Ah. I see. The array controller is posting a KVO notification in the
middle of the fetch operation. You can work around the problem by
disabling "Use Lazy Fetching" on the array controller.
- Ben
_______________________________________________
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