parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.89k stars 735 forks source link

Can't Save New Record if beforeSave exists #150

Closed ridergeek closed 9 years ago

ridergeek commented 9 years ago

When using Android SDK to save a new record in a class that has a beforeSave function in cloud code, all fields get changed to undefined. If I remove the beforeSave function, the record saves just fine. If I use IOS or REST to save a record with the same beforeSave function, the record saves just fine. The beforeSave code doesn't really matter - it can be as simple as "response.success()" and all fields become undefined.

grantland commented 9 years ago

Could you provide some more info to help us repro this such as, but not limited to:

parse-github-bot commented 9 years ago

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

ridergeek commented 9 years ago

Android version: compileSdkVersion 22 Javascript version: latest Parse hosted cloud code or webhooks: Parse hosted cloud code Android code:

private void saveParseObject(final ParseFile fullImageData, ParseFile thumbImageData) {        
    ParseObject obj = new ParseObject("chart");
    obj.put("owner", mUser);
    obj.put("name", mEtChartName.getText().toString());
    obj.put("designer", mParseObject);
    obj.put("notes", mEtNotes.getText().toString());
    if (fullImageData != null) {
        obj.put("fullImage", fullImageData);
        obj.put("thumbnail", thumbImageData);
        obj.put("chargeCredit", true);
    }
    obj.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                mProgressDialog.hide();
                mUser.increment("chartCount", 1);
                mUser.saveEventually();

                if (fullImageData !=null) {
                    Toast.makeText(getActivity(),
                            "Successfully saved the new chart. You have " + (mUser.getInt("photoCredits") - 1) + " photos credits remaining.",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(),
                            "Successfully saved the new chart.",
                            Toast.LENGTH_SHORT).show();
                }
                MainActivity activity = (MainActivity) getActivity();
                activity.removeAllStack();

            } else {
                mProgressDialog.hide();
                Toast.makeText(getActivity(),
                        e.getLocalizedMessage(),
                        Toast.LENGTH_SHORT).show();
            }
        }
    });
}

Javascript code:

 Parse.Cloud.beforeSave("chart", function(request, response) {
     console.log("Running beforesave")
     response.success()
 });

Android OS version: 4.2.2 (Samsung Galaxy S3) and Android Studio Emulator 5.x

I copied the cloud code to a different project thinking it might be an issue with my Parse project. I had the exact same problem on both projects - columns all change to "undefined".

ridergeek commented 9 years ago

P.S. I upgraded to Parse Android SDK 1.10.2 and still have the same problem.

ridergeek commented 9 years ago

Here's the log output when I use beforeSave. The "update changed to {}" is what baffles me.

I2015-09-23T23:05:51.493Z]v85 before_save triggered for chart for user YUUdJazO4j: Input: {"original":null,"update":{"ACL":{"YUUdJazO4j":{"read":true,"write":true}},"designer":{"type":"Pointer","className":"designer","objectId":"sl5smLJb2A"},"name":"BeforeSaveTest","notes":"","owner":{"type":"Pointer","className":"_User","objectId":"YUUdJazO4j"}}} Result: Update changed to {} I2015-09-23T23:05:51.529Z]Running beforesave

ridergeek commented 9 years ago

Did dome additional testing today and it appears to be a bug in JS 1.6.x. I changed to JS 1.5.0 and everything worked fine. Closing this issue and opening a new issue for Javascript.