Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object.save() make all the keys dirty #106

Open
cg-cnu opened this issue Apr 13, 2015 · 2 comments
Open

object.save() make all the keys dirty #106

cg-cnu opened this issue Apr 13, 2015 · 2 comments

Comments

@cg-cnu
Copy link

cg-cnu commented Apr 13, 2015

I modified few attributes on an object and saved it.
gameScore.score = 2061
gameScore.save()
When querying from beforesave cloud code, request.object.dirtyKeys() returns all keys dirty... instead of just the modified keys.

@danrobinson
Copy link
Collaborator

This bug is due to the way ParsePy currently saves Objects--by sending a PUT request with the entire object's data, thus resaving every field. The way other SDKs (such as the JavaScript SDK) implement saving is by keeping a running tally of all changes made to the object, and only sending only those changes to the server.

I can work on this, but it might take up to a week to fix. In the meantime, is it possible to write the beforeSave cloud code to work around using dirtyKeys, maybe by comparing fields to the object's previous fields? Something like:

query = new Parse.Query("GameScore");
query.get(request.object.id, {
    success: function(oldObject) {
        if (request.object.get("score") !== oldObject.get("score")) {
            // score is dirty
        }
    },
    error: function(error) {
        console.error("Got an error " + error.code + " : " + error.message);
    }
});

It's an extra database hit, but it might work for now.

@cg-cnu
Copy link
Author

cg-cnu commented Apr 15, 2015

That would be awesome, saves a lot of pain. I was in a hurry to get it working; so, stored a separate attribute in the table as shootMail. If I modify the values I intend to shoot mail I put it to true and later in the cloudcode shoot the mail and revert it back to false. That does the job for now, but it would be helpful to shoot different mails based on the attributes changed with out much work in the client code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants