-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Milestone
Description
hi again,
I noticed that when the background context can't be saved at the end of the marshaling process, i.e. for a validation issue, the request succeed and it returns an array of objectIDs anyway. Is it correct? The new data wasn't saved in the main context and the API just returns an array of the old values of the local persisted data.
Here is the code:
+ (NSArray *)objectIDsForRecords:(NSArray *)records
onMainContext:(NSManagedObjectContext *)mainContext
fromBackgroundContext:(NSManagedObjectContext *)backgroundContext {
[mainContext MMRecord_startObservingWithContext:backgroundContext];
NSError *coreDataError = nil;
if ([backgroundContext save:&coreDataError] == NO) {
NSString *coreDataErrorString = [NSString stringWithFormat:@"Core Data error occurred with code: %d, description: %@",
coreDataError.code,
coreDataError.localizedDescription];
NSString *errorDescription = [NSString stringWithFormat:@"Unable to save background context while populating records. MMRecord import operation unsuccessful. %@",
coreDataErrorString];
MMRecordOptions *options = [self currentOptions];
MMRecordDebugger *debugger = options.debugger;
NSDictionary *parameters = [debugger parametersWithKeys:@[MMRecordDebuggerParameterErrorDescription] values:@[errorDescription]];
[debugger handleErrorCode:MMRecordErrorCodeCoreDataSaveError withParameters:parameters];
}
[mainContext MMRecord_stopObservingWithContext:backgroundContext];
NSMutableArray *objectIDs = [NSMutableArray array];
for (MMRecord *record in records) {
[objectIDs addObject:[record objectID]];
}
return objectIDs;
}Metadata
Metadata
Assignees
Labels
No labels