sbonami / PFIncrementalStore

Offline Parse with Core Data Persistence, an NSIncrementalStore subclass.
http://sbonami.github.io/PFIncrementalStore/
MIT License
97 stars 15 forks source link

Error inserting new relation #51

Open callzhang opened 10 years ago

callzhang commented 10 years ago

In Basic Example, I added a new Artist object with relation to Song, which also has relation to Genre:

Artist *artist = [NSEntityDescription insertNewObjectForEntityForName:@"Artist" inManagedObjectContext:context];
Song *song = [NSEntityDescription insertNewObjectForEntityForName:@"Song" inManagedObjectContext:context];
Genre *genre = [NSEntityDescription insertNewObjectForEntityForName:@"Genre" inManagedObjectContext:context];
artist.artistName = @"New";
genre.genreName = @"My genre";
song.songTitle = @"Song title";
song.songArtist = artist;
song.songGenre = genre;
NSError *err;
[context save:&err];
if (err) {
    NSLog(@"%@", err.description);
}

But the IncrementalStore threw an error as follows. What's rather interesting is that the code works sometime and doesn't work some other times. I tried to delete the relation definition on Parse.com and it still works. It seems that the framework doesn't use relation definition on Parse to get the related item.

2014-05-11 02:16:02.878 Basic Example[3147:1303] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)' * First throw call stack: ( 0 CoreFoundation 0x02e1b1e4 exceptionPreprocess + 180 1 libobjc.A.dylib 0x02b9a8e5 objc_exception_throw + 44 2 Basic Example 0x0013df7b PFSaveManagedObjectContextOrThrowInternalConsistencyException + 331 3 Basic Example 0x0014997c 80-[PFIncrementalStore newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke_5 + 28 4 CoreData 0x00d1984f developerSubmittedBlockToNSManagedObjectContextPerform + 95 5 libdispatch.dylib 0x0312f4d0 _dispatch_client_callout + 14 6 libdispatch.dylib 0x0311c740 _dispatch_barrier_sync_f_invoke + 58 7 libdispatch.dylib 0x0311c3ea dispatch_barrier_sync_f + 89 8 CoreData 0x00d1977f -[NSManagedObjectContext performBlockAndWait:] + 127 9 Basic Example 0x00149924 80-[PFIncrementalStore newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke_4 + 196 10 CoreData 0x00d1984f developerSubmittedBlockToNSManagedObjectContextPerform + 95 11 CoreData 0x00d1978c -[NSManagedObjectContext performBlockAndWait:] + 140 12 Basic Example 0x0014974e __80-[PFIncrementalStore newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke_3 + 1758 13 Basic Example 0x0014b20c -[PFIncrementalStore insertOrUpdateObjects:ofEntity:withContext:error:completionBlock:] + 460 14 Basic Example 0x00148f4c 80-[PFIncrementalStore newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke_2 + 1180 15 CoreData 0x00d91fe3 developerSubmittedBlockToNSManagedObjectContextPerform_privateasync + 83 16 libdispatch.dylib 0x0312f4d0 _dispatch_client_callout + 14 17 libdispatch.dylib 0x0311d047 _dispatch_queue_drain + 452 18 libdispatch.dylib 0x0311ce42 _dispatch_queue_invoke + 128 19 libdispatch.dylib 0x0311dde2 _dispatch_root_queue_drain + 78 20 libdispatch.dylib 0x0311e127 _dispatch_worker_thread2 + 39 21 libsystem_pthread.dylib 0x0345edab _pthread_wqthread + 336 22 libsystem_pthread.dylib 0x03462cce start_wqthread + 30 ) libc++abi.dylib: terminating with uncaught exception of type NSException

luke0x commented 10 years ago

@callzhang Did you discover a way to fix this? Experiencing the same issue with the Basic Example + MagicalRecord Example apps.

@sbonami Curious if you have any thoughts too...

callzhang commented 10 years ago

@luke0x I pretty much fixed it on my last pull request. Since @sbonami provided me the admin rights, I haven't had a chance to get out of my daily work but I have some plan to do it very soon.

luke0x commented 10 years ago

@callzhang Nice, I'll take a look. Thanks for getting back.