Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
476 stars 70 forks source link

Uncaught exception 'RLMException', reason: 'Path '(null)' is not valid #77

Closed olivierto closed 8 years ago

olivierto commented 8 years ago

Hello, i'm facing an issue with the RBQFetchedResultsController it crashes systematically... the crash log : crashlog.txt

Turns out to be a "RBQSafeObject" that has no "realm" attached and no "realmConfiguration". I'm using realm 0.95.3.

Here is the code i used to instantiate the controller :

    @try {
        id <AppServices> service  = self.viewModel.services;
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userId == %@",service.userService.userID];

        RBQFetchRequest *fetchRequest = [RBQFetchRequest fetchRequestWithEntityName:@"Photo"
                                                                            inRealm:[RLMRealm defaultRealm]
                                                                          predicate:predicate];

        RLMSortDescriptor *sortDescriptor = [RLMSortDescriptor sortDescriptorWithProperty:@"creationTime"
                                                                                ascending:NO];

        fetchRequest.sortDescriptors = @[sortDescriptor];

        self.fetchedResultsController = [[RBQFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                                               sectionNameKeyPath:nil
                                                                                        cacheName:@"YoobiMyPhotoFetchRC"];

        self.fetchedResultsController.delegate = self;

        [self.fetchedResultsController performFetch];
    }
    @catch (NSException *exception) {
        LOG_ERROR(0,@"Error with RBQFetch exception : %@",exception);
    }

I'm trying to fix it in a fork but not finding the right way... ANy help would be much appreciated :)

Bye!

crsantos commented 8 years ago

Turns out to be a "SafeObject" that has no "realm" attached and no "realmConfiguration".

Usually when I got that symptom, I forgot to add the object to notificationManager:

    [[RBQRealmChangeLogger defaultLogger] didAddObject:object];
    // or 
    [[RBQRealmChangeLogger defaultLogger] didChangeObject:object];

Make sure you do that before calling [RLMRealm commitWriteTransaction]

olivierto commented 8 years ago

Usually when I got that symptom, I forgot to add the object to notificationManager:

Nope... unfortunatly all my methods that changes or add objects are already using the logger...

[db beginWriteTransaction];
        [db addObjects:returnedObjects];
        [[RBQRealmChangeLogger defaultLogger] didAddObjects:returnedObjects];
        [db commitWriteTransaction];
crsantos commented 8 years ago

Sorry! My fault, wrong error. I meant to say: did you add the object to the RLMRealm?

[realm addOrUpdateObject:object];

That was my realm problem. Im sorry for mis-leading you

olivierto commented 8 years ago

here is my code :

[db beginWriteTransaction];
[db addObjects:returnedObjects];
[[RBQRealmChangeLogger defaultLogger] didAddObjects:returnedObjects];
[db commitWriteTransaction];
olivierto commented 8 years ago

OMG !! i tryed with [db addOrUpdateObjects:returnedObjects]; And it worked !! I don't understand why because it's only an insert operation :o thanks a lot dude!

crsantos commented 8 years ago

No problem mate :) That haunted me for at least 2h.

I don't understand why because it's only an insert operation

If it's an add operation, you can force the addObjects But addOrUpdateObjects checks that for you.