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
{{ message }}
Repository navigation
Using revert in beforeSave triggers doesn't return the correct response #7838
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
🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
Activity
parse-github-assistant commentedon Mar 11, 2022
Thanks for opening this issue!