Roobiq/RBQFetchedResultsController

When using addNotified() I am getting a 'Object must be from the Realm being queried' error

Closed this issue · 4 comments

Our UITableView was not getting the change notifications (data fetched with RealmResultsController):
realm.add(object, update: type.primaryKey() != nil)
but once we changed to
realm.addWithNotification(object, update: type.primaryKey() != nil)
it started crashing hard, although it was updating the delegate methods then.

2016-04-06 16:01:02.347 XXX[27792:268230] *** Terminating app due to uncaught exception 'Invalid value origin', reason: 'Object must be from the Realm being queried'
*** First throw call stack:
(
0 CoreFoundation 0x000000010956ee65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108fe7deb objc_exception_throw + 48
2 Realm 0x0000000105dce2b1 ZL15RLMPreconditionbP8NSStringS0_z + 657
3 Realm 0x0000000105df82ca _ZN12_GLOBAL__N_128add_link_constraint_to_queryERN5realm5QueryE23NSPredicateOperatorTypeRKNS_15ColumnReferenceEP9RLMObject + 1370
4 Realm 0x0000000105df5c79 _ZN12_GLOBAL__N_126do_add_constraint_to_queryIJNS_15ColumnReferenceEU8__strongP11objc_objectEEEvRN5realm5QueryE15RLMPropertyType23NSPredicateOperatorTypemDpT + 1353
5 Realm 0x0000000105de9532ZN12_GLOBAL__N_123add_constraint_to_queryINS_15ColumnReferenceEU8__strongP11objc_objectEEvRN5realm5QueryE15RLMPropertyType23NSPredicateOperatorTypemT_T0 + 658
6 Realm 0x0000000105dd2f47ZN12_GLOBAL__N_134update_query_with_value_expressionEP9RLMSchemaP15RLMObjectSchemaRN5realm5QueryEP8NSStringP11objc_objectP21NSComparisonPredicate + 967
7 Realm 0x0000000105dcfcf6 _ZN12_GLOBAL__N_127update_query_with_predicateEP11NSPredicateP9RLMSchemaP15RLMObjectSchemaRN5realm5QueryE + 5286
8 Realm 0x0000000105dcec22 _ZN12_GLOBAL__N_127update_query_with_predicateEP11NSPredicateP9RLMSchemaP15RLMObjectSchemaRN5realm5QueryE + 978
9 Realm 0x0000000105dce460 _Z27RLMUpdateQueryWithPredicatePN5realm5QueryEP11NSPredicateP9RLMSchemaP15RLMObjectSchema + 336
10 Realm 0x0000000105ed515d _ZZ35-[RLMResults objectsWithPredicate:]ENK4$_10clEv + 269
11 Realm 0x0000000105ed2a86 _ZL15translateErrorsIZ35-[RLMResults objectsWithPredicate:]E4$_10EDaOT_P8NSString + 38
12 Realm 0x0000000105ed29f8 -[RLMResults objectsWithPredicate:] + 72
13 RBQFetchedResultsController 0x0000000105cdd5df -[RBQFetchRequest fetchObjects] + 271
14 RBQFetchedResultsController 0x0000000105cd1781 -[RBQFetchedResultsController createStateObjectWithFetchRequest:realm:cache:cacheRealm:] + 1489
15 RBQFetchedResultsController 0x0000000105ccdc50 -[RBQFetchedResultsController calculateChangesWithAddedSafeObjects:deletedSafeObjects:changedSafeObjects:realm:] + 2208
16 RBQFetchedResultsController 0x0000000105ccd1d4 __58-[RBQFetchedResultsController registerChangeNotifications]_block_invoke + 1396
17 RBQFetchedResultsController 0x0000000105ce0376 -[RBQRealmNotificationManager sendNotificationsWithRealm:entityChanges:] + 518
18 RBQFetchedResultsController 0x0000000105ce2550 __50-[RBQRealmChangeLogger registerChangeNotification]_block_invoke + 256
19 Realm 0x0000000105ec08b9 -[RLMRealm sendNotifications:] + 1065
20 Realm 0x0000000105ecc7fb _ZN12_GLOBAL__N_121RLMNotificationHelper10did_changeERKNSt3__16vectorIN5realm14BindingContext13ObserverStateENS1_9allocatorIS5_EEEERKNS2_IPvNS6_ISB_EEEE + 107
21 Realm 0x0000000105ef698b _ZN5realm5_impl11transaction6commitERNS_11SharedGroupEPNS_14BindingContextE + 395
22 Realm 0x0000000105eefac8 _ZN5realm5Realm18commit_transactionEv + 456
23 Realm 0x0000000105ec0c95 -[RLMRealm commitWriteTransaction:] + 53
24 Realm 0x0000000105ec0f4e -[RLMRealm transactionWithBlock:error:] + 158
25 RealmSwift 0x00000001063784b1 _TFC10RealmSwift5Realm5writefS0_FzFT_T_T + 209
26 XXX 0x000000010528b190 TZFC6XXX18PersistenceManager3addfMS0_FTC10RealmSwift6Object14fromWriteBlockSb_CS1_5Realm + 480
27 XXX 0x00000001052453f0 TZFC6XXX7Message11saveMessagefMS0_FTV10SwiftyJSON4JSON10chatThreadCS_10ChatThread_GSqS0 + 7952
28 XXX 0x000000010541e59bTZFC6XXX7Message23messagesFromAPIResponsefMS0_FCS_11APIResponseT + 5755
29 XXX 0x00000001052107b6TZFC6XXX14APISyncManagerP33_56FDCEDBD7F938B6203CBE93E62664E123populateMessagesFromAPIfMS0_FCS_11APIResponsePSs9AnyObject + 294
30 XXX 0x000000010536359fTFZFC6XXX9APIClient23performTaskInBackgroundFMS0_FVS_21APIBackgroundableTaskFT_T_U_FCS_11APIResponseT + 511
31 XXX 0x000000010535be9cTPA__TFZFC6XXX9APIClient23performTaskInBackgroundFMS0_FVS_21APIBackgroundableTaskFT_T_U_FCS_11APIResponseT + 172
32 XXX 0x0000000105363297 TTRXFo_oC6XXX11APIResponse_dT__XFo_iS0__iT
+ 23
33 XXX 0x000000010535bf41 TPA__TTRXFo_oC6XXX11APIResponse_dT__XFo_iS0__iT__13 + 81
34 XXX 0x0000000105363b30 TTRXFo_iC6XXX11APIResponse_iT__XFo_oS0__dT + 32
35 XXX 0x0000000105363c63TFFC6XXX9APIClientP33_632183BA90AB5BFCA689BD5720141B8C20handleSocketResponseFS0_FTGSaPSs9AnyObject__3ackGSqC22Socket_IO_Client_Swift16SocketAckEmitter__T_U_FT_T + 291
36 XXX 0x00000001051f9b67 TTRXFo__dT__XFdCb__dT
+ 39
37 libdispatch.dylib 0x000000010a835e5d _dispatch_call_block_and_release + 12
38 libdispatch.dylib 0x000000010a85649b _dispatch_client_callout + 8
39 libdispatch.dylib 0x000000010a83c8ec _dispatch_queue_drain + 2215
40 libdispatch.dylib 0x000000010a83be0d _dispatch_queue_invoke + 601
41 libdispatch.dylib 0x000000010a83ea56 _dispatch_root_queue_drain + 1420
42 libdispatch.dylib 0x000000010a83e4c5 _dispatch_worker_thread3 + 111
43 libsystem_pthread.dylib 0x000000010ab8e4de _pthread_wqthread + 1129
44 libsystem_pthread.dylib 0x000000010ab8c341 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

realm.add(object, update: type.primaryKey() != nil) ChangeLogger.defaultLogger().didChangeObject(object)

Gives this error:

libc++abi.dylib: terminating with uncaught exception of type realm::IncorrectThreadException: Realm accessed from incorrect thread.

It has been resolved, thanks.