Skip to content

Using revert in beforeSave triggers doesn't return the correct response #7838

Closed

Description

@dblythy

New Issue Checklist

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

Logs

Activity

  1. parse-github-assistant commented on Mar 11, 2022

    @parse-github-assistant

    Thanks for opening this issue!

    • 🚀 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.
  2. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    on Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions