Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

javascript - Parse request.object.get("KEY") always returns undefined

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...