magicalpanda/MagicalRecord — Issue #147: Manually calling save inside performSaveDataOperationInBackgroundWithBlock fails to notify parent context on completion
Author: duanefields
Created: 2012-03-01 20:14:03+00:00
State: open

Inside my performSaveDataOperationInBackgroundWithBlock I'm calling [context save] on the local context. I do this for during an operation that has 3 independent steps, so once I finish a step I call save. Anyhow, here's what I'm seeing.

When I save, the main context seems to be notified of changes, but when I'm done it all disappears.

Here's what I think is happening. If I have no unsaved changes at the end of the block (because I've already called save on the local context) then it hits this code inside saveDataWithBlock:block:errorHandler

if ([localContext hasChanges])
{
[localContext MR_saveWithErrorHandler:errorHandler];
}

Since there's not any changes, it skips the call to localContext_MR_saveWithErrorHandler which in turn skips the call to the parent context:

[[self parentContext] MR_saveWithErrorHandler:errorCallback];

Do I have this correct? Seems like the fix is to not check for 'hasChanges', with the side effect being you'll get a possible empty notification back to the parent context.