Parse request.object.get("KEY") always returns undefined
Asked Answered
S

1

8

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.

Selfeffacement answered 19/9, 2015 at 11:0 Comment(2)
Can you show what's in request.object?Paramount
request.object is undefined, it simply isn't there somehow (for the other developer, my account is still fine) - but request.user exists. When the object doesn't pass cloudcode, everything is there, all the fields are correctly set.Selfeffacement
S
8

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"
    }
  }
}
Selfeffacement answered 21/9, 2015 at 22:17 Comment(5)
Good work! Make sure to report this as a bug so the Parse team can fix itEggplant
I've same error how did you change global.json? where can I find it?Vaivode
found it in the .parse.local hidden file and changed 1.4.2 and everything is fine thank you very much, saved my day. :)Vaivode
Thanks for pointing that out, changed my answer to give you a hint about the missing global.json file.Selfeffacement
It's in .parse.local now. Changing the version there worked for me as well, thanks.Esemplastic

© 2022 - 2024 — McMap. All rights reserved.