'NSInternalInconsistencyException', reason: 'Cannot add object with entity 'TestResult' to cache for entity of 'TestResult''

52 views
Skip to first unread message

Jonathon Rogoff

unread,
Oct 29, 2014, 4:54:46 PM10/29/14
to res...@googlegroups.com
I am receiving this error:

2014-10-29 15:20:20.897 MyProject[2487:4507] *** Assertion failure in -[RKEntityByAttributeCache addObjects:completion:], /Users/jrogoff/Desktop/MyProject/Pods/RestKit/Code/CoreData/RKEntityByAttributeCache.m:333


2014-10-29 15:20:20.900 MyProject[2487:4507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot add object with entity 'TestResult' to cache for entity of 'TestResult''


while processing the response mapping for the following network request:

            NSMutableURLRequest *request = [[RKObjectManager sharedManager]

                                           multipartFormRequestWithObject:testResult

                                           method:RKRequestMethodPOST path:path parameters:nil

                                           constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

               [formData appendPartWithFileData:UIImagePNGRepresentation(testResult.capturedImage)

                                           name:@"imageFileData"

                                       fileName:@"photo.png"

                                       mimeType:@"image/png"];

           }];


          RKObjectRequestOperation *operation = [[RKObjectManager sharedManager]


                                                   managedObjectRequestOperationWithRequest:request


                                                   managedObjectContext:context


                                                   success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {


                                                       NSLog(@"Successfully uploaded testResult %@", testResult);


                                                       TestResult *nextTest = mappingResult.firstObject;


                                                       //Perform business logic for next test here


                                                   }


                                                   failure:^(RKObjectRequestOperation *operation, NSError *error) {


                                                       NSLog(@"Unable to upload testResult: %@", error);


                                                   }];


            [[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation];


I expect the assertion error has something to do with confusion caused by uploading a finished TestResult object (as defined by a RKRequestDescriptor for TestResult plus the image file) and receiving a new TestResult object as json in the response (parsed by a RKResponseDescriptor mapping for TestResult).  Less likely, it may also be a weird threading issue caused by nesting the above code inside a for loop for situations where there are multiple finished TestResults ready to be uploaded.

Regardless, there is only one TestResult class in my project, so I do not understand how it fails to be the same kind of entity as itself.  If I comment out the assertion, then my code executes successfully and I can process the next TestResult without any problems, so at least in this case the failed assertion appears to be erroneous.  Is there a better solution that does not require commenting out this assertion?
Reply all
Reply to author
Forward
0 new messages