Using propertiesToFetch in a nested MOContext causes crash
| Originator: | jdelStrother | ||
| Number: | rdar://11355254 | Date Originated: | |
| Status: | Resolved: | ||
| Product: | Product Version: | ||
| Classification: | Reproducible: |
01-May-2012 06:38 PM Jonathan del Strother:
Summary:
When using nested NSManagedObjectContexts, trying to issue a fetch request with propertiesToFetch set will result in a crash inside the child context.
Steps to Reproduce:
Create an NSMainQueueConcurrencyType parent context
Create an NSPrivateQueueConcurrencyType context as its child
Run the following:
[child performBlockAndWait:^{
NSFetchRequest* fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Event"];
fetchRequest.propertiesToFetch = [NSArray arrayWithObject:@"timeStamp"];
NSError* error=nil;
NSLog(@"%@", [child executeFetchRequest:fetchRequest error:&error]);
}];
Expected Results:
The child fetches some results
Actual Results:
A crash with the following stack trace:
* thread #1: tid = 0x1f03, 0x01838caa libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.3
frame #0: 0x01838caa libobjc.A.dylib`objc_exception_throw
frame #1: 0x00fc943d CoreData`-[NSSQLiteConnection handleCorruptedDB:] + 253
frame #2: 0x00ed827c CoreData`-[NSSQLiteConnection fetchResultSet:usingFetchPlan:] + 156
frame #3: 0x00ee0da3 CoreData`newFetchedRowsForFetchPlan_MT + 1571
frame #4: 0x00ecc084 CoreData`-[NSSQLCore newRowsForFetchPlan:] + 356
frame #5: 0x00ecb619 CoreData`-[NSSQLCore objectsForFetchRequest:inContext:] + 713
frame #6: 0x00ecb0b0 CoreData`-[NSSQLCore executeRequest:withContext:error:] + 224
frame #7: 0x00eca45d CoreData`-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1837
frame #8: 0x00ec82fd CoreData`-[NSManagedObjectContext executeFetchRequest:error:] + 605
frame #9: 0x00f1b32b CoreData`-[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:] + 203
frame #10: 0x00f1b1fc CoreData`__-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_1 + 412
frame #11: 0x00f1afd4 CoreData`_perform + 84
frame #12: 0x00f1ae6d CoreData`-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 237
frame #13: 0x00ec82fd CoreData`-[NSManagedObjectContext executeFetchRequest:error:] + 605
frame #14: 0x000024d6 CoreData`__59-[ABAppDelegate application:didFinishLaunchingWithOptions:]_block_invoke_0 + 326 at ABAppDelegate.m:42
frame #15: 0x00f1ad03 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 99
frame #16: 0x0406f951 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 61
frame #17: 0x0406fe00 libdispatch.dylib`dispatch_barrier_sync_f + 62
frame #18: 0x00f1ac58 CoreData`-[NSManagedObjectContext performBlockAndWait:] + 136
- followed by "CoreData: error: The database appears corrupt. (invalid primary key)" in the console.
With com.apple.CoreData.SQLDebug enabled, that fetch request results in this SQL from the parent context:
SELECT t0.Z_ENT, t0.Z_PK, t0.ZTIMESTAMP FROM ZEVENT t0
but this SQL from the child :
SELECT t0.ZTIMESTAMP FROM ZEVENT t0
Seems like it's not fetching the primary key?
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Anyone know a workaround?