In a Core Data document-based app, I open an old document which must be 
migrated to the current version.  Automatic migration apparently succeeds -- 
the document opens.  However, when I make a change and Save, it fails with 
"Could not merge changes".

Since this problem seems to involve merging, I read about NSErrorMergePolicy 
and learned that a conflict of the type I'm seeing is between managed object 
contexts.  I conclude that it could only occur if I have fetched the same 
object into two different mocs.  I have not done this, that I know of.  I do 
sometimes copy objects to an internal moc with an in-memory store, but this is 
always done by inserting a new object, copying attributes, and re-connecting 
corresponding relationships.  The Migration process momentarily opens a 
persistent store and coordinator, but not a managed object context as far as I 
can see.

Nonetheless, I decided to try and override -mergePolicy in my NSManagedObject 
subclass, returning NSMergeByPropertyObjectTrumpMergePolicy.  Indeed, this 
"fixed" the "problem".  Closing and re-opening the document, everything looks 
OK.

But other stuff is wrong too.  A typical item in the "conflictList" includes 
entries like this:

* Key = object.  Value = A Cocoa -description of a particular object.
* Key = snapshot.  Value = a deep (with children) dictionary of properties of 
usually the same object but sometimes a different object.
* Key = cachedRow.  Value = a shallow (no children) dictionary of attributes of 
an object which is always different than either of the first two.

No object identifiers are given in this error info.  I determine that objects 
are "different" by examining their attributes (name, type, parent, etc.) and 
verifying their self-consistency.  

According to the interpretations of these keys given in the "Constants" section 
of NSManagedObject documentation, the presence of the above key/value entries 
indicates a conflict between the between the managed object context and the 
persistent store coordinator.  Which mocs?  Also, this document says that those 
'object', 'snapshot' and 'cachedRow' refer to the same object, not different 
objects as I am seeing.  So, it looks as though the saving process somehow got 
haywired.

Regarding the mapping, my model has a dozen entities.  I changed a few 
attributes, in two of these entities, between the old and new versions.  But 
the entity of all of the reportedly conflicted objects is one of the ten 
entities that were *not* changed in the revision.  I verified this again by 
"Show Differences" in the mapping model.

What might be the origin of the "conflicts"?  Where is this other moc?

Thanks very much,

Jerry Krinock_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to