magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Concurrent creating with saveWthBlock:completion: returns contextDidSave == NO && error == nil but all is saved. #1237

Open psi-gh opened 8 years ago

psi-gh commented 8 years ago

For testing purpose i have the following code which called from main thread (in viewDidLoad method).

for (int i = 0; i < 50; i++) {
    [MagicalRecord saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
        [FieldDescription MR_createEntityInContext:localContext];
        // there is nothing to config, no primary attribute or smth, 
        // just need to create new entity and save it
    } completion:^(BOOL contextDidSave, NSError * _Nullable error) {
        if (!contextDidSave) {
            DDLogError(@"Error saving field description: %@", error.localizedDescription);
        }
    }];
}

In a result, a part of entities saving is completed with contextDidSave == YES, but other part completed with contextDidSave == NO && error == nil. I get following messages in logs with it: NO CHANGES IN ** MagicalRecord Root Saving Context ** CONTEXT - NOT SAVING Seems like some of entities was not saved. But despite of that all entities eventually saved in storage. I can't rely on such odd result of saving operation to make my system reliable. What i'm missing and how can i make this works without such behaviour?

p.s. I know that if i place all of 50 those calls inside saveWithBlock it will work, but my current architecture won't allow me that because i'm making a lot of MagicalRecord calls from asynchronously operations.

psi-gh commented 8 years ago

Can please anyone tell me if this a bug or my misunderstanding?

airrons commented 6 years ago

same with me . have you solved this issue now?