Closed
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
As discussed here, using revert
doesn't work due to revert
removing ops for the key, so the keys' update won't be returned by the API.
I.e, for an update of a key foo, the server will respond:
{ 'foo' : 'bar' }
And the client will merge that with the existing object, so
{'name': 'f'}
would become {'name': 'f', 'foo': 'bar'}
However, when revert
is used, the server responds with {}
, which gets merged with the clients' JSON of { 'foo' : 'bar' }
, meaning the client thinks the key update was successful.
Steps to reproduce
it('should revert in beforeSave', async () => {
Parse.Cloud.beforeSave('MyObject', ({object}) => {
if (!object.existed()) {
object.set('count', 0);
return object;
}
object.revert('count');
return object;
});
const obj = await new Parse.Object('MyObject').save();
expect(obj.get('count')).toBe(0);
obj.set('count', 10);
await obj.save();
expect(obj.get('count')).toBe(0); // test fails, JS SDK thinks count was successfully updated
await obj.fetch();
expect(obj.get('count')).toBe(0); // test passes
});
Actual Outcome
Keys are updated
Expected Outcome
Keys to be reverted
Environment
Server
- Parse Server version:
alpha
- Operating system:
macos
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
localhost
Database
- System (MongoDB or Postgres):
mongo
- Database version:
5
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
local
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
JS
- SDK version:
latest