From 47eed616efb9596a234da05a0ad2182872692482 Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Thu, 21 Feb 2013 23:02:23 -0500 Subject: [PATCH] Fix crash due to execution of `RKDeleteInvalidNewManagedObject` from outside of the dispatch queue of the `NSManagedObjectContext` that owns the object. fixes #1251 --- Code/CoreData/RKManagedObjectMappingOperationDataSource.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/CoreData/RKManagedObjectMappingOperationDataSource.m b/Code/CoreData/RKManagedObjectMappingOperationDataSource.m index 4a63a45c2a..5e5f6f4fe8 100644 --- a/Code/CoreData/RKManagedObjectMappingOperationDataSource.m +++ b/Code/CoreData/RKManagedObjectMappingOperationDataSource.m @@ -123,6 +123,7 @@ static id RKMutableCollectionValueWithObjectForKeyPath(id object, NSString *keyP return nil; } +// Pre-condition: invoked from the managed object context of the given object static BOOL RKDeleteInvalidNewManagedObject(NSManagedObject *managedObject) { if ([managedObject isKindOfClass:[NSManagedObject class]] && [managedObject managedObjectContext] && [managedObject isNew]) { @@ -326,7 +327,9 @@ - (BOOL)commitChangesForMappingOperation:(RKMappingOperation *)mappingOperation // Attempt to establish the connections and delete the object if its invalid once we are done NSOperationQueue *operationQueue = self.operationQueue ?: [NSOperationQueue currentQueue]; NSBlockOperation *deletionOperation = [NSBlockOperation blockOperationWithBlock:^{ - RKDeleteInvalidNewManagedObject(mappingOperation.destinationObject); + [[(NSManagedObject *)mappingOperation.destinationObject managedObjectContext] performBlockAndWait:^{ + RKDeleteInvalidNewManagedObject(mappingOperation.destinationObject); + }]; }]; for (RKConnectionDescription *connection in connections) {