简体   繁体   中英

Parse.com - Error 101 when saving new PFObject

I'm creating a new PFObject, setting some objects on it, then saving it like so:

// Add a new 'madeTitle' Activity Object
PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
[madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
[madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
[madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
[madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
[madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

// ACL's
PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[ACL setPublicReadAccess:YES];
[ACL setWriteAccess:YES forUser:[PFUser currentUser]];
madeTitleActivity.ACL = ACL;


[madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

    if (succeeded) {
        // ...
    }
    else {
        NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
    }
}];

But I'm getting the following error:

2013-10-22 10:55:12.546 WSPhoto[2064:7b4b] Error: object not found for update (Code: 101, Version: 1.2.6)
2013-10-22 10:55:12.552 WSPhoto[2064:707] madeTitleActivity saveInBackgroundWithBlock -- error = Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x8966c0 {code=101, error=object not found for update}

I've dealt with the error before, but it has been with updating objects and having ACL issues. I haven't had this error code when creating and saving a new object.

I've checked all the objects that I'm setting and they're all returning valid objects.

I've also saved a few other Activity objects successfully and from what I can tell the code looks exactly the same.


EDIT: Expanded code including the CloudCode function call that the madeTitleActivity code is nested in

 [PFCloud callFunctionInBackground:@"setCommentIsTitle"
                   withParameters:@{@"userID":[[PFUser currentUser] objectId],
                     @"objectId":[aComment objectId],
                     @"photoObjectId":[self.photo objectId],
                     @"previousCommentObjectId":[previousTitleComment objectId],
                     @"isTitle":[NSNumber numberWithBool:YES],
                     @"previousCommentObjectIsTitle":[NSNumber numberWithBool:NO]}
                                block:^(NSMutableDictionary *results , NSError *error) {

    if (!error) {
        // Add a new 'madeTitle' Activity Object
        PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
        [madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
        [madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
        [madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
        [madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
        [madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

        // ACL's
        PFACL *madeTitleACL = [PFACL ACLWithUser:[PFUser currentUser]];
        [madeTitleACL setPublicReadAccess:YES];
        [madeTitleACL setWriteAccess:YES forUser:[PFUser currentUser]];
        madeTitleActivity.ACL = madeTitleACL;

        [madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

            NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- called");

            if (succeeded) {
               // ..
            }
            else {
                NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
            }
        }];
    }

    else {
        NSLog(@"etCommentIsTitle PFCloud  -- error = %@", error);
    }
}];

This:

Error: object not found for update

Means that you are trying to save an object with a relationship to some other object that hasn't been saved yet. You can't do that because it doesn't exist.

You need to find out what that other object it and ensure that it's saved first.


Note that you can use one of the saveAll... methods to batch save a number of new objects and both avoid this kind of issue and obtain some efficiency gains.

Also reminder don't try setting the ObjectId when trying to save a new object. This usually isn't an issue unless you accidentally blow away your db and try to push it back up.

It relate to ACL, please check your dashboard for the data column "ACL"

The write should lock on specific user ID. you need change it from your dashboard to update its permission to

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

You can check more detail on my reply in this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM