Parse request.object.get(“KEY”) always returns undefined

折月煮酒 提交于 2019-11-26 14:43:52

问题


I have a strange problem over here. I have a project built with Parse.com as a backend (using cloudcode to verify some things when a connection to the database is made). Everything works just as it should do.

But here comes the problem. Another developer reported to me that there is something wrong because he is getting 'undefined' every time he tries to call request.object.get('KEY')in CloudCode. This developer uses the exact same codebase as I do.

So I decided to have a look at it. While with my Parse account, every application works fine (even newly created ones), with the Parse account of the other developer, not a single new application we created seems to work with the exact same code. And it is getting even stranger - creating a completely new Parse account and a new application produces the same errors while my personal account and applications continue to work fine.

So what is the problem? We are using CloudCode, and here is sample code (in javascript) of a beforeSave method:

Parse.Cloud.beforeSave('Activity', function(request, response) {
   var currentUser = request.user;
   var objectUser = request.object.get('fromUser');
   if(!currentUser || !objectUser) {
     response.error('An Activity should have a valid fromUser.');
   } else {
     response.success();
   }
});

And every time request.object.get('KEY') returns undefined, for every key I previously defined in the iOS code before uploading the PFObject. Note that with my personal account everything is fine...

I have already seen this thread, however deleting ACL's didn't do the trick. request.object.get() stays undefined while request.useris defined for every tested Parse account except mine.

EDIT 1

I also had a look at the activity object just before it is uploaded, and there all the fields are properly set.

EDIT 2

After removing the cloud code completely, the objects are correctly being uploaded to Parse, with all the fields being the way they were set via the iOS client. So it seems that something is wrong with Parse's cloud code, but as soon as an object passes through cloud code, it looses all its fields.


回答1:


Finally I was able to solve this. This is definitely a bug in Parse's Javascript SDK. I changed the Javascript SDK version in the global.json back to version "1.4.2" instead of "latest", uploaded this to the cloudcode folder and everything went back to normal.

You can also test other versions, maybe v1.5.0 is working too, but as soon as I found out v1.4.2 worked fine, I didn't try out more recent versions.

EDIT

So, I discovered, that Parse must have changed something in their command line tool. It seems that the global.json file isn't there anymore if you create your CloudCode folder with the most recent version of their command line tool. However, you can manually create it and upload the complete folder to your Parse app.

This is how my CloudCode folder looks like, just for example: CloudCode folder contains three subfolders

• cloud - containing cloud code files

• config - containing the global.json file

• public - containing the index.html file

The global.json file contains these lines of code:

{
  "global": {
    "parseVersion": "1.4.2"
  },
  "applications": {
    "YOUR_PARSE_APPS_NAME": {
      "applicationId": "YOUR_APP_ID",
      "masterKey": "YOUR_APP_MASTER_KEY"
    },
    "_default": {
      "link": "YOUR_PARSE_APPS_NAME"
    }
  }
}


来源:https://stackoverflow.com/questions/32667395/parse-request-object-getkey-always-returns-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!