You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setup a beforeSave hook for some class, let's say Event;
Create/Save an object, without setting the properties foo and otherKey with no changes, but setting a third one, thirdKey for example, to some value.
Add the following code sample:
Code sample
Parse.Cloud.beforeSave("Event",function(request,response){varevent=request.object;console.log(event.dirtyKeys());if(!request.master){varprotectedKeys=["foo","otherKey"];//only masterKey can change the protectedKeysfor(i=0;i<protectedKeys.length;i++){varkey=protectedKeys[i];if(event.dirty(key)){response.error("External users are not authorized to change the key '"+key+"'. It's value is: ("+event.get(key)+"). Dirty keys are: "+event.dirtyKeys());return;}}}});
Result
This same code works totally fine in the hosted Parse.com Cloud Code.
Unfortunately, event.dirty('foo') returns true, while dirtyKeys() does not contain the property 'foo'. I show an alert in my app when this error happens, and we can see the error:
The text was updated successfully, but these errors were encountered:
natanrolnik
changed the title
In beforeSave, dirty(:key) returns a different value than expected from dirtyKeys
In beforeSave, for a new object, dirty(:key) returns a different value than expected from dirtyKeys
May 24, 2016
natanrolnik
changed the title
In beforeSave, for a new object, dirty(:key) returns a different value than expected from dirtyKeys
In beforeSave, when creating a new object, dirty(:key) returns a different value than expected from dirtyKeys
May 24, 2016
Could you provide more complete reproduction steps? The beforeSave, and a cURL request (or series of cURL requests) should be sufficient to repro the problem.
So with the help of @drew-gross I figured out what was the reason.
My Parse.com Cloud Code was running the version 1.2.19 of the Parse JS SDK. At some point, in the dirty(key) method, this change was introduced, and for new objects being saved, any key passed to the dirty(key) method will return true, even though the key wasn't defined at all.
Environment Setup
Steps to reproduce
beforeSave
hook for some class, let's sayEvent
;foo
andotherKey
with no changes, but setting a third one,thirdKey
for example, to some value.Code sample
Result
This same code works totally fine in the hosted Parse.com Cloud Code.

Unfortunately,
event.dirty('foo')
returnstrue
, whiledirtyKeys()
does not contain the property 'foo'. I show an alert in my app when this error happens, and we can see the error:Mentioning @nlutsenko as he worked on
dirtyKeys
andbeforeSave
on #614 and @drew-gross onbeforeSave
on #1884The text was updated successfully, but these errors were encountered: