Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
dblythy opened this issue Mar 11, 2022 · 1 comment
Closed
4 tasks done
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@dblythy
Copy link
Member

dblythy commented Mar 11, 2022

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

@parse-github-assistant
Copy link

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.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Mar 11, 2022
@dblythy dblythy closed this as completed Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants