parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

cloudcode: Parse.User( ) + save => error: code=206, message=cannot modify user

Open ideastouch opened this issue 10 years ago • 5 comments

Environment Setup

Parse iOS SDK version: v1.12.0 iOS version: 9.3 (15E65) Parse JS version: v1.8.3 (NodeJS 5.10.0)'

PFUser.enableRevocableSessionInBackgroundWithBlock is called after initializations of Parse. Parse Server is new and the user session and authentications settings are to true:

User Sessions
  • Require revocable sessions: Yes
  • Expire inactive sessions: Yes
  • Revoke session on password change: Yes
User Authentication
  • new methods by default: Yes
  • Allow username and password-based authentication: Yes
  • Allow anonymous users: Yes

Steps to reproduce

Define a cloud function that update some property in a user and call it from a iOS client. An example of the cloud function is below:

Parse.Cloud.define('messageUnreadCountCloudFunction', function(request, response){
    var user = request.user
    user.set('propertyName', 'new value')
    user.save({useMasterKey:true}).then(
        function(object){
             response.success(count) },
        function(error){
             response.error('Save fail')
    } )
} )

Then the call to user.save will fail with a error code 206, , see Logs at case First case.

Work around:

If it is called to Parse.Object.saveAll instead of save the error is gone. In our case we replace the line user.save().then( by the call below: Parse.Object.saveAll([user], { useMasterKey: true }).then(

Then the error is gone, see Logs at case Case work around.

Logs/Trace

Server running with VERBOSE=1 are:

First case
verbose: POST /parse/functions/messageUnreadCountCloudFunction { host: 'localhost:1337',
  'x-parse-client-version': 'i1.12.0',
  accept: '*/*',
  'x-parse-session-token': '**********************************',
  'x-parse-application-id': '****************************************',
  'x-parse-client-key': '****************************************',
  'x-parse-installation-id': '****************************************',
  'x-parse-os-version': '9.3 (15E65)',
  'accept-language': 'en-us',
  'accept-encoding': 'gzip, deflate',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '2',
  'user-agent': 'TroupeFit/82 CFNetwork/758.3.15 Darwin/15.4.0',
  connection: 'keep-alive',
  'x-parse-app-build-version': '82',
  'x-parse-app-display-version': '3.0' } {}
verbose: PUT /parse/classes/_User/PQauDXIuWZ {
 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 5.10.0)',
  accept: '*/*',
  'content-type': 'text/plain',
  host: 'localhost:1337',
  'content-length': '304',
  connection: 'close' } {
  "aliveDate": {
    "__type": "Date",
    "iso": "2016-04-28T18:13:20.267Z"
  },
  "useMasterKey": true
}
verbose: error: code=206, message=cannot modify user PQauDXIuWZ
Case work around
verbose: POST /parse/functions/messageUnreadCountCloudFunction { host: 'localhost:1337',
  'x-parse-client-version': 'i1.12.0',
  accept: '*/*',
  'x-parse-session-token': 'r:9b0eac99a951885c0adf44af06648e27',
  'x-parse-application-id': 'lSmGQ9tk2ljFSq7NPeB6Bu9V6AYeUVPEtuFbiBHU',
  'x-parse-client-key': 'HHwYAobW8U2SV2P1oERSUumfCvyG75TcrHi5Roow',
  'x-parse-installation-id': 'c82844ae-4f4e-47b7-9814-de3e9de4893a',
  'x-parse-os-version': '9.3 (15E65)',
  'accept-language': 'en-us',
  'accept-encoding': 'gzip, deflate',
  'content-type': 'application/json; charset=utf-8',
  'content-length': '2',
  'user-agent': 'TroupeFit/82 CFNetwork/758.3.15 Darwin/15.4.0',
  connection: 'keep-alive',
  'x-parse-app-build-version': '82',
  'x-parse-app-display-version': '3.0' } {}
verbose: POST /parse/batch { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 5.10.0)',
  accept: '*/*',
  'content-type': 'text/plain',
  host: 'localhost:1337',
  'content-length': '344',
  connection: 'close' } {
  "requests": [
    {
      "method": "PUT",
      "body": {
        "aliveDate": {
          "__type": "Date",
          "iso": "2016-04-28T23:41:29.388Z"
        }
      },
      "path": "/parse/classes/_User/PQauDXIuWZ"
    }
  ]
}
verbose: {
  "response": [
    {
      "success": {
        "updatedAt": "2016-04-28T23:41:29.401Z"
      }
    }
  ]
}
verbose: {
  "response": {
    "result": "user aliveDate value updated"
  }
}
verbose: POST /parse/batch { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 5.10.0)',
  accept: '*/*',
  'content-type': 'text/plain',
  host: 'localhost:1337',
  'content-length': '344',
  connection: 'close' } {
  "requests": [
    {
      "method": "PUT",
      "body": {
        "aliveDate": {
          "__type": "Date",
          "iso": "2016-04-28T23:41:29.393Z"
        }
      },
      "path": "/parse/classes/_User/PQauDXIuWZ"
    }
  ]
}
verbose: {
  "response": [
    {
      "success": {
        "updatedAt": "2016-04-28T23:41:29.759Z"
      }
    }
  ]
}

ideastouch avatar Apr 29 '16 01:04 ideastouch

It seems you are using object.save incorrectly - the options should be in the 2nd parameter. Please see: https://parse.com/docs/js/api/classes/Parse.Object.html#methods_save

Try this instead:

user.save(null, {useMasterKey:true});

saveAll has a different function signature which is why your workaround works.

steven-supersolid avatar Apr 30 '16 14:04 steven-supersolid

You right. Txs!!!

ideastouch avatar May 02 '16 20:05 ideastouch

When I am using the above specified syntax, the user.save function is working correctly and user gets updated but it still returns me the 206 error.

for (var i = 0; i < adminUsers.length; i++) {
       if (adminUsers[i].get("companyId") == params.companyId) {
       adminUsers[i].set("challenge", challenge);
       changedAdminUsers.push(adminUsers[i]);
       promises.push(
               adminUsers[i].save(null,{useMasterKey: true})
        );
   }
}

ERROR: [null,{"code":206,"message":"Cannot modify user ."}]

Any idea why.

pushparajsamant avatar Aug 12 '16 07:08 pushparajsamant

Hi @pushparajsamant , I think that you should open a fresh tread with your question. BTW: I don't know why your code fails.

ideastouch avatar Aug 12 '16 19:08 ideastouch

Thanks will do.

pushparajsamant avatar Aug 14 '16 08:08 pushparajsamant