0
votes

Saving a user causes Error: object not found for update (Code: 101, Version: 1.2.19)

   [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
        if (!error) {
            [PFUser currentUser].location = geoPoint;
            [[PFUser currentUser] save];
        }
    }];

what am I doing wrong?

http post request https://api.parse.com/2/update

{
    "iid": "[redacted]",
    "classname": "_User",
    "data": {
        "email": "[email protected]",
        "objectId": "[redacted]"
    },
    "session_token": "[redacted]",
    "v": "i1.2.19",
    "uuid": "[redacted]"
}

response

{
    "code": 101,
    "error": "object not found for update"
}
3

3 Answers

1
votes

I have the same problem as you, I done some testing and figure out root cause:

  • Create new class GameScore as document
  • Do the same create and update object and find out it works well
  • Check the "ACL" columns and compare to your problem data. See?

Works ACL, I done modify for * to make it clear
Works ACL, I done modify for * to make it clear

enter image description here
Failed ACL.

As you could see the write privilege lock to user "6iIv5XWZvM", that's why your update will "not found object"

You could change data record directly to "*" to let your update works well.

OK! Here is solution as follow:

  1. Change every record "ACL" data col as follow:

    {"*":{"write":true,"read":true}}

  2. You need login PFUSer as specific user to change ACL to public. For my case use objectId will be "6iIv5XWZvM". I need set password and login info and use code to login and modify it. Detail iOS code as follow:

     //iOS Sample
     [PFUser logInWithUsernameInBackground:@"USERNAME" password:@"PASSWORD" block:^(PFUser *user, NSError *error) {
        if (user) {
            PFQuery *query = [PFQuery queryWithClassName:CLASS_NAME];
            [query findObjectsInBackgroundWithBlock:^(NSArray *objs, NSError *error) {
                for (PFObject *obj in objs) {
                    PFACL *defaultACL = [PFACL ACL];
                    [defaultACL setPublicReadAccess:YES];
                    [defaultACL setPublicWriteAccess:YES];
                    [obj setACL:defaultACL];
                    [obj saveInBackground];
                }
            }];
        } else {
            // The login failed. Check error to see why.
            }
    }];
    

However remember to add following setting before you save new data, if you don't want to happen anymore (note: it will be security concern)

//It is iOS code sample.
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];
0
votes

Try this, i'm using this, when i need to save objects for the current user. Hope it will help.

        PFUser *user = [PFUser currentUser];
        [user setObject:geoPoint forKey:@"location"];

        [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error){
                NSLog(@"Error %@ %@", error, [error userInfo]);
            }
        }];
0
votes

The error : "object not found for update" append when the you try to save an object that the user does not have ACL access.

In order to let the user change the object you need to set PFACL permission when you create the object :

For a specific user :

PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setWriteAccess:YES forUserId:userID];
object.ACL = groupACL;

For a all users :

PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setPublicWriteAccess:YES];
object.ACL = groupACL;