Using `revert` in beforeSave function

Hi guys,

I often use object.revert in a beforeSave trigger to track masterKey only fields, such as count.

However, when a client attempts to mutate count, using revert removes the key count from the data payload, so the JS SDK thinks that they key count was successfully updated.

This means that the key count appears to be updated, even though it was reverted.

Here’s an example of the functionality:

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
});

My question is; is this a bug in Parse Server or the JS SDK? Or is this expected functionality (cc @Manuel @davimacedo)

Thanks!!

I guess that’s the problem: REST API Guide | Parse

The response of the create endpoint is only objectId and createdAt fields. So there is currently no way for the SDK to know that some field has changed in a trigger.

We’d need to improve Parse Server to also return any field that was changed in triggers during the save operation.