lhunath / UbiquityStoreManager

Implements Core Data + iCloud, deals with all the nasty stuff and gives you a clean API.
http://lhunath.github.io/UbiquityStoreManager
Apache License 2.0
391 stars 37 forks source link

Getting an optimistic locking failure #51

Closed NorbNorb closed 10 years ago

NorbNorb commented 10 years ago

I'm trying to use the UbiquityStoreManager. I've installed my app in the simulator and on a device. After editing objects on the device, I get the following crash error now after each start of the app.

2014-02-07 22:10:31:273 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading store...
2014-02-07 22:10:31:273 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Will load cloud store.
2014-02-07 22:10:31:274 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Clearing stores...
2014-02-07 22:10:31:274 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Will clear stores.  Notifying application to reset its UI.
2014-02-07 22:10:31:315 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading cloud store: 1DA646F2-BC01-47A9-AF10-C9927BF675A2, v1 (definite).
2014-02-07 22:10:31:316 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] migrationStoreURL: (null)
2014-02-07 22:10:31:316 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] migrationStoreOptions: {
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSReadOnlyPersistentStoreOption = 1;
}
2014-02-07 22:10:31:322 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] cloudSafeForSeeding: 0
2014-02-07 22:10:31:326 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] Will NOT migrate to cloud store from: MyAppUbiquityStore.sqlite (strategy: 2).
2014-02-07 22:10:31:329 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading store: 1DA646F2-BC01-47A9-AF10-C9927BF675A2.sqlite
2014-02-07 22:10:31.344 MyApp[59621:1303] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](754): CoreData: Ubiquity:  AZau~sim08080FB0-40C3-503D-9CE4-B15138E48D42:1DA646F2-BC01-47A9-AF10-C9927BF675A2
Using local storage: 1
2014-02-07 22:10:31:359 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Successfully loaded cloud store.
2014-02-07 22:10:31:360 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Finished loading cloud store (UbiquityStoreErrorCauseNoError).  Notifying application to refresh its UI.
2014-02-07 22:10:31.415 MyApp[59621:3507] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](754): CoreData: Ubiquity:  AZau~sim08080FB0-40C3-503D-9CE4-B15138E48D42:1DA646F2-BC01-47A9-AF10-C9927BF675A2
Using local storage: 0
2014-02-07 22:10:31.924 MyApp[59621:1303] CoreData: warning: An NSManagedObjectContext delegate overrode fault handling behavior to silently delete the object with ID '0x136716a0 <x-coredata://6AE50E77-A609-4D06-810C-9F785E27A08B/Flower/p358>' and substitute nil/0 for all property values instead of throwing.
Description of exception being thrown: 'optimistic locking failure'

What's the cause of this? This is my merge policy setting:

- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didLoadStoreForCoordinator:(NSPersistentStoreCoordinator *)coordinator
                     isCloud:(BOOL)isCloudStore
{
    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
    moc.persistentStoreCoordinator = coordinator;
    moc.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy;
    _managedObjectContext = moc;
}
lhunath commented 10 years ago

What's the actual exception, message and back trace?

On 7 February 2014 16:19, NorbNorb notifications@github.com wrote:

I'm trying to use the UbiquityStoreManager. I've installed my app in the simulator and on a device. After editing objects on the device, I get the following crash error now after each start of the app.

2014-02-07 22:10:31:273 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading store... 2014-02-07 22:10:31:273 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Will load cloud store. 2014-02-07 22:10:31:274 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Clearing stores... 2014-02-07 22:10:31:274 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Will clear stores. Notifying application to reset its UI. 2014-02-07 22:10:31:315 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading cloud store: 1DA646F2-BC01-47A9-AF10-C9927BF675A2, v1 (definite). 2014-02-07 22:10:31:316 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] migrationStoreURL: (null) 2014-02-07 22:10:31:316 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] migrationStoreOptions: { NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; NSReadOnlyPersistentStoreOption = 1; } 2014-02-07 22:10:31:322 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] cloudSafeForSeeding: 0 2014-02-07 22:10:31:326 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: [DEBUG] Will NOT migrate to cloud store from: MyAppUbiquityStore.sqlite (strategy: 2). 2014-02-07 22:10:31:329 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Loading store: 1DA646F2-BC01-47A9-AF10-C9927BF675A2.sqlite 2014-02-07 22:10:31.344 MyApp[59621:1303] -PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:: CoreData: Ubiquity: AZau~sim08080FB0-40C3-503D-9CE4-B15138E48D42:1DA646F2-BC01-47A9-AF10-C9927BF675A2 Using local storage: 1 2014-02-07 22:10:31:359 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Successfully loaded cloud store. 2014-02-07 22:10:31:360 MyApp[59621:4867] -[UbiquityStoreManager log:] [Line 555] UbiquityStoreManager: Finished loading cloud store (UbiquityStoreErrorCauseNoError). Notifying application to refresh its UI. 2014-02-07 22:10:31.415 MyApp[59621:3507] -PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:: CoreData: Ubiquity: AZau~sim08080FB0-40C3-503D-9CE4-B15138E48D42:1DA646F2-BC01-47A9-AF10-C9927BF675A2 Using local storage: 0 2014-02-07 22:10:31.924 MyApp[59621:1303] CoreData: warning: An NSManagedObjectContext delegate overrode fault handling behavior to silently delete the object with ID '0x136716a0 x-coredata://6AE50E77-A609-4D06-810C-9F785E27A08B/Flower/p358' and substitute nil/0 for all property values instead of throwing. Description of exception being thrown: 'optimistic locking failure'

What's the cause of this? This is my merge policy setting:

  • (void)ubiquityStoreManager:(UbiquityStoreManager )manager didLoadStoreForCoordinator:(NSPersistentStoreCoordinator )coordinator isCloud:(BOOL)isCloudStore { NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; moc.persistentStoreCoordinator = coordinator; moc.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy; _managedObjectContext = moc; }

— Reply to this email directly or view it on GitHubhttps://github.com/lhunath/UbiquityStoreManager/issues/51 .

Maarten Billemont (lhunath) me: http://www.lhunath.com – business: http://www.lyndir.comhttp://masterpasswordapp.com

NorbNorb commented 10 years ago

That's all I get from the console. I've added a breakpoint for objc_exception_throw, but it stops in assembler code. Where can I get more details about this exception? This is the backtrace:

* thread #5: tid = 0x6603c7, 0x02a4388a libobjc.A.dylib`objc_exception_throw, queue = 'NSOperationQueue Serial Queue, stop reason = breakpoint 1.1
    frame #0: 0x02a4388a libobjc.A.dylib`objc_exception_throw
    frame #1: 0x0101ef2e CoreData`-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 4414
    frame #2: 0x0104bccc CoreData`-[NSManagedObjectContext save:] + 764
    frame #3: 0x011704c7 CoreData`-[_PFUbiquityRecordImportOperation main] + 10615
    frame #4: 0x0250b829 Foundation`-[__NSOperationInternal _start:] + 671
    frame #5: 0x02488558 Foundation`-[NSOperation start] + 83
    frame #6: 0x0250daf4 Foundation`__NSOQSchedule_f + 62
    frame #7: 0x036f14b0 libdispatch.dylib`_dispatch_client_callout + 14
    frame #8: 0x036df07f libdispatch.dylib`_dispatch_queue_drain + 452
    frame #9: 0x036dee7a libdispatch.dylib`_dispatch_queue_invoke + 128
    frame #10: 0x036dfe1f libdispatch.dylib`_dispatch_root_queue_drain + 83
    frame #11: 0x036e0137 libdispatch.dylib`_dispatch_worker_thread2 + 39
    frame #12: 0x03a7ddab libsystem_pthread.dylib`_pthread_wqthread + 336
lhunath commented 10 years ago

Most likely, you're doing a save on an old MOC.