Deleted records reappear after app restart #332

brspurri opened this Issue Dec 4, 2012 · 4 comments


None yet
2 participants

brspurri commented Dec 4, 2012

Hi there,

I'm scratching my head on this one, but it's happening on both the device and simulator (in my case).

I save all my records using the following code:

[[NSManagedObjectContext MR_defaultContext] MR_saveInBackgroundErrorHandler:^(NSError *error) {
            [Logger log:[NSString stringWithFormat:@"Error saving to CoreData:: %@", [error description]]];
        } completion:^(void) {
            [Logger log:[NSString stringWithFormat:@"Preset saved to CoreData successfully"]];

And later I delete a record using the code:

PhotoPresetEntity *presetEntity = [PhotoPresetEntity MR_findFirstByAttribute:@"identifier"
    id localPresetEntity = [presetEntity inContext:[NSManagedObjectContext MR_defaultContext]];
    if(localPresetEntity) {
        [localPresetEntity MR_deleteInContext:[NSManagedObjectContext MR_defaultContext]];
        [Logger log:[NSString stringWithFormat:@"Deleting preset: %@\n", [presetEntity identifier]]];

where identifier is a property of PhotoPresetEntity.

When run, it deletes the record - or so it appears to be deleted because if the delete method is run again with the same identifier that was originally deleted, presetEntity is nil (as expected).

HOWEVER, when I restart my app, it REAPPEARS! AGHHHHH. Why might this be? I'm running all my MR commands in the MR_defaultContext.

Does anyone have any pointers on how to debug this? I'm at a complete loss.



tonyarnold commented Dec 4, 2012

Are you saving the delete? The snippet of code around the delete does not save the delete (and thus commit the change to disk).

@ghost ghost assigned tonyarnold Dec 4, 2012

brspurri commented Dec 4, 2012


No, I wasn't, but adding the line:
[[NSManagedObjectContext MR_defaultContext] MR_save];

after the deleteInContext' didn't help. Could there be another way tosave` that I'm missing in this case?


tonyarnold commented Dec 4, 2012

Hi @brspurri — the behaviour of MR_save has changed in a recent release, and only persists to the parent context, not to all the way to disk — could you try wrapping the whole deletion in a similar save block to your initial example and see if that helps?

brspurri commented Dec 4, 2012

That did the trick! Thanks a million! Issue opened and closed within 10 minutes :-)

@brspurri brspurri closed this Dec 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment