drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

mergeWithCompletion throws error when deleting objects #65

Closed ghost closed 10 years ago

ghost commented 10 years ago

I have a simple model, with parent and children belonging to parent. Synching generally works, but when I delete a child object, I get an error like this:

Could not find object with identifier to remove from relationship. Skipping: 9D394E51-1696-4623-84D5-F853816971A4-2985-0000026B921D7768

I'm not generating custom global IDs.

It looks like, within applyToManyRelationshipChanges:toObject:withObjectsByGlobalId:, the child object is not contained in the NSMapTable objectsByGlobalId.

Here is what the map table looks like:

NSMapTable { [6] 4FDAD411-10B5-4445-82B0-D71EF547C55D-2910-0001091721C2C6FD -> <Account: 0x8b32eb0> (entity: Account; id: 0x8b31e80 x-coredata://DEE9FA64-9F5A-4E50-9A7C-CCB00590F6E9/Account/p2 ...}) }

Account is the parent entity, so it looks like the map table only contains mapping for the parent object, not the child object that is being deleted. Any idea why?

drewmccormack commented 10 years ago

Is this just a log message, or does it actually cause an error with the merge failing?

I suspect it may just be a warning message. It is acceptable for a deleted object to be missing, but it does log it as a warning.

What do you see in your app? Is the data what you expect after the sync?

drewmccormack commented 10 years ago

By the way, global ids are always generated to track objects on different devices, even if you won't provide them.

ghost commented 10 years ago

The delete doesn't propagate to the other device when I see this happen. Where would I begin to look to debug the underlying issue? events.sqlite maybe?

Also, how do I view content of cdeevent files in plain text?

Thanks

drewmccormack commented 10 years ago

Are you absolutely certain the delete does not propagate? This error message is actually expected in certain circumstances, and shouldn't cause any adverse effects. Sometimes a change doesn't immediately make it over, due to iCloud lags. Can you verify that it still doesn't appear, even after several syncs? Are you making sure to merge the background save changes in the persistentStoreEnsemble:didSave... method, and then reloading data in your interface if appropriate? It could be you are retaining a deleted object in your interface.

Drew

On 02 Dec 2013, at 08:02, coco342 notifications@github.com wrote:

The delete doesn't propagate to the other device when I see this happen. Where would I begin to look to debug the underlying issue? events.sqlite maybe?

Also, how do I view content of cdeevent files in plain text?

Thanks

— Reply to this email directly or view it on GitHub.

drewmccormack commented 10 years ago

By the way, it is not so easy to see inside the cdeevent files yet, because they are binary core data stores. I have a half baked tool to extract them, but you are probably best for now to intercept the CDEEventMigrator importing the events, in a method like

But first, I really recommend double checking the delete is not really going through, but your UI is not updating to reflect it. (You could even just kill the app, and relaunch, to see if it is still there.)

Drew

On 02 Dec 2013, at 08:06, Drew McCormack drewmccormack@mac.com wrote:

Are you absolutely certain the delete does not propagate? This error message is actually expected in certain circumstances, and shouldn't cause any adverse effects. Sometimes a change doesn't immediately make it over, due to iCloud lags. Can you verify that it still doesn't appear, even after several syncs? Are you making sure to merge the background save changes in the persistentStoreEnsemble:didSave... method, and then reloading data in your interface if appropriate? It could be you are retaining a deleted object in your interface.

Drew

On 02 Dec 2013, at 08:02, coco342 notifications@github.com wrote:

The delete doesn't propagate to the other device when I see this happen. Where would I begin to look to debug the underlying issue? events.sqlite maybe?

Also, how do I view content of cdeevent files in plain text?

Thanks

— Reply to this email directly or view it on GitHub.

ghost commented 10 years ago

Actually, upon further testing, the delete does propagate, I just needed to trigger in turn on each device a few times manually. I still get the "Could not find object with identifier to remove" popping up each time for the same object identifiers, but sync seems to be working okay.

drewmccormack commented 10 years ago

Yeah, iCloud can sometimes take a little while to move files over, so that is probably what you see.

The message is overzealous, and I have removed it. It is a normal state of a affairs to not find the deleted object in relationship updates. Doesn’t even warrant a warning.

Thanks for keeping me on my toes ;)

ghost commented 10 years ago

Sounds good!