Post

Replies

Boosts

Views

Activity

Batch insert error when unique constraint is set on multiple attributes
I'm testing out Core Data batch insert. The performance is amazing!! Data gets imported in a just a couple hundreds of milliseconds. New rows are inserted and existing rows are updated. I ran into 1 problem though.... If the unique constraint is set with multiple attributes, batch insert will fail. Below is the call stack of the failed operation: 2020-10-06 00:05:44.900901-0700 TestHostingApp[17605:1541912] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'error in batch insertion: Error Domain=NSCocoaErrorDomain Code=134050 "(null)" UserInfo={NSExceptionOmitCallstacks=true, _NSCoreDataOptimisticLockingFailureConflictsKey=()}' \*\*\* First throw call stack: ( 0   CoreFoundation                      0x00007fff2043a126 __exceptionPreprocess + 242 1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48 2   CoreFoundation                      0x00007fff20439f4f +[NSException raise:format:] + 0 3   Foundation                          0x00007fff207881ca -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4   SchedKit2_Tests                     0x0000000104fb85a7 -[NSManagedObjectContext(SchedBatchInsert) batchInsertWithEntityName:objects:] + 391 5   SchedKit2_Tests                     0x0000000104fb3194 __92+[BatchImport importEntityWithName:confID:batchSize:context:queue:formatHandler:completion:]_block_invoke_2.73 + 180 6   CoreData                            0x00007fff25109933 developerSubmittedBlockToNSManagedObjectContextPerform + 154 7   libdispatch.dylib                   0x00007fff20106534 _dispatch_client_callout + 8 8   libdispatch.dylib                   0x00007fff2010c425 _dispatch_lane_serial_drain + 715 9   libdispatch.dylib                   0x00007fff2010cfa0 _dispatch_lane_invoke + 403 10  libdispatch.dylib                   0x00007fff20117591 _dispatch_workloop_worker_thread + 782 11  libsystem_pthread.dylib             0x00007fff5dcd8a3d _pthread_wqthread + 290 12  libsystem_pthread.dylib             0x00007fff5dcd7b77 start_wqthread + 15 ) libc++abi.dylib: terminating with uncaught exception of type NSException My entity has this constrain configuration: Constraints: eventID,sessionID The context where batch insert operation has mergeByPropertyObjectTrumpMergePolicy policy set. Is this a known limitation? (i.e. I can only set unique constraint on 1 attribute in order to have batch insert work correctly?)
3
0
1.3k
Oct ’20