Strange problem when try to update user

Hi guys,
I’m having a strange behavior when try to update the user. I’ll explain step by step.
1- A user saves an object in a relation linked with itself and all is ok.
2- The user deletes this object from that relation and all is ok.
3- Here’s the problem. When the user tries to save a new object, the console gives me this message
“FAULT = Entity with the specified ID cannot be found: Id - 22654AE3-FB04-73B0-FFD8-E018FD471200 <Entity with the specified ID cannot be found: Id - 22654AE3-FB04-73B0-FFD8-E018FD471200>”
The objectID and the userID are both different from the id in the message.
If user logs out then logs in again and tries to save the object, all works good but the problem appears again when the user tries to remove the object.
My SDK is the latest, just updated.

…and when I try to login with Facebook, my app crashes on this line of code

NSString *userId = backendless.userService.currentUser.objectId;

This bug is in the latest sdk. I tried with the previous release and no crashes here, all works well.

Why?

NB: Maybe these are two different problems, because the first occurs with both sdk’s versions and the second problem occurs only with the latest sdk.
Please let me know if I have to create another topic.

Please provide a sample code demonstrating the issue, or attach your project here.

This is the method used to update the user. Please keep in mind that when this method is called, “userVespa” has been already saved on the server.
The asynchronous method returns the fault.

  • (void)updateUserWithAddedVespa:(UserVespa *)userVespa {
    // Create relation with user
    NSMutableArray *linkedVespas = [backendless.userService.currentUser getProperty:kUserVespasRelation];
    if (!linkedVespas) {
    linkedVespas = [NSMutableArray array];
    }
    [linkedVespas addObject:userVespa];

    [backendless.userService.currentUser setProperty:kUserVespasRelation object:linkedVespas];

    // Update user
    [backendless.userService update:backendless.userService.currentUser response:^(BackendlessUser *updated) {

      [[NSNotificationCenter defaultCenter]postNotificationName:kNotificationUserVespaSaved object:userVespa];
    

    } error:^(Fault *fault) {
    NSLog(@“FAULT = %@ <%@>”, fault.message, fault.detail);
    }];

}

Please keep in mind that the method above works good but it stops working when I delete a Vespa from the relation, as I have written above. Below the code used to remove a vespa.

  • (void)removeUserVespa:(UserVespa *)vespa {

    // Get relation

    NSMutableArray *linkedVespas = [backendless.userService.currentUser getProperty:kUserVespasRelation];
    // Remove the vespa

    [linkedVespas removeObject:vespa];
    // Update property

    [backendless.userService.currentUser setProperty:kUserVespasRelation object:linkedVespas];

    // Update user…

    [backendless.userService update:backendless.userService.currentUser response:^(BackendlessUser *updated) {

      //...then remove the vespa
    
      [backendless.persistenceService remove:vespa response:^(NSNumber *success) {
    
      } error:^(Fault *fault) {
    
          //NSLog(@"removeUserVespa_FAULT = %@ &lt;%@&gt;", fault.message, fault.detail);
    
      }];
    

    } error:^(Fault *fault) {

      //NSLog(@"userUpdate_FAULT = %@ &lt;%@&gt;", fault.message, fault.detail);
    

    }];

}

Hi Francesco,

You didn’t provide your UserVespa class (I think it is inherited from BackendlessUser class - and this is BAD idea).

I’ve implemented your scenario in sample project (see in attachment), you could investigate TestCUserService target (in Objective-C) and let me know how it goes for you.

Regard,
Slava

TestUserService.zip (19.28MB)

Hi Slava,
I have tried to run your sample project but it doesn’t work, I’m receiving an error with this message “ld: library not found for -lPods” and I think it is related to cocoa pod that I don’t use.
Btw, the UserVespa class isn’t inherited from BackendlessUser. All my code works well every times I call the APIs shown above in the previous message.
The problem is when I delete an object (UserVespa, and this API works without any faults). After that, if I try to save a new UserVespa I receive the error.

So, the scenario is:
1- I add a UserVespa —>OK.
2- I add another UserVespa —>OK
3- I remove a UserVespa —>OK
4- I add a new UserVespa —>doesn’t work
5- Log out
6- Log in
7- I add a UserVespa —>OK

I think that if my code contained errors, it would give me always the same error also in the cases 1, 2 and 7. But it doesn’t work only in the case 4, after removing an old UserVespa.

You should load TestUserService.xcworkspace (it create with CocoaPods)

Please provide your UserVespa class (and all its properties classes, if they are) and your appId - here or to support@backendless.com (marked “topic/strange-problem-when-try-to-update-user”)

Hi Slava, I have sent an email to support@backendless.com

Hi Francesco,

I have sent you a sample project by email. Please try it and let me know how it goes for you.

Regards,
Slava

Hi Slava,
I solved this problem, there was a little error in my code.

Thank you for your help!