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

Set Objects in afterFind and afterLiveQueryEvent triggers #7310

Closed
4 of 6 tasks
dblythy opened this issue Apr 1, 2021 · 5 comments · Fixed by #7311
Closed
4 of 6 tasks

Set Objects in afterFind and afterLiveQueryEvent triggers #7310

dblythy opened this issue Apr 1, 2021 · 5 comments · Fixed by #7311
Labels
state:released Released as stable version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@dblythy
Copy link
Member

dblythy commented Apr 1, 2021

New Issue Checklist

Issue Description

With the way Parse handles pointers, if you set a query a Parse.Object and set it to req.object using afterFind or afterLiveQueryEvent, Parse converts it to a pointer and strips all fields.

Steps to reproduce

afterFind:

  it('can set a pointer object in afterFind', async done => {
    //save obj for query
    const obj = new Parse.Object('MyObject');
    await obj.save();
    
    Parse.Cloud.afterFind('MyObject', async ({objects}) => {
      const otherObject = new Parse.Object('Test');
      otherObject.set('foo', 'bar');
      await otherObject.save();
      // set object
      objects[0].set('Pointer', otherObject);
      // set first object field 'Pointer' to object
      expect(objects[0].get('Pointer').get('foo')).toBe('bar');
      return objects;
    });

    const query = new Parse.Query('MyObject');
    query.equalTo('objectId', obj.id);
    const [obj2] = await query.find();
    const pointer = obj2.get('Pointer');
    expect(pointer.get('foo')).toBe('bar');
    // should be able to access 'foo' on the pointer, but it returns null.
    done()

  });

afterLiveQueryEvent:

Parse.Cloud.afterLiveQueryEvent('TestObject', async ({object}) => {
  const query = new Parse.Query('Test2');
  const obj = await query.first();
  object.set('obj', obj);
});
subscription.on('update', (object) => {
  expect(object.get('obj')).toBeDefined();
  expect(object.get('obj').get('foo')).toBe('bar');
  // foo will be null
  done();
});

Actual Outcome

Fields on pointer objects are empty

Expected Outcome

Data should propagate down

Failing Test Case / Pull Request

  • 🤩 I submitted a PR with a fix and a test case.
  • 🧐 I submitted a PR with a failing test case.

Environment

Server

  • Parse Server version: FILL_THIS_OUT
  • Operating system: FILL_THIS_OUT
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): FILL_THIS_OUT

Database

  • System (MongoDB or Postgres): FILL_THIS_OUT
  • Database version: FILL_THIS_OUT
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): FILL_THIS_OUT

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): FILL_THIS_OUT
  • SDK version: FILL_THIS_OUT

Logs

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Apr 4, 2021
@mtrezza
Copy link
Member

mtrezza commented Apr 4, 2021

Thanks for reporting.

I classified this as a bug. To help determine the severity of this bug:

  • Is there a known workaround until this bug is fixed?

@dblythy
Copy link
Member Author

dblythy commented Apr 4, 2021

The workaround is to fetch the pointer on the frontend after the object has been returned.

@mtrezza
Copy link
Member

mtrezza commented Apr 4, 2021

Thanks, I classified this as bug with severity S3:

@mtrezza mtrezza added the S3 label Apr 4, 2021
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Nov 1, 2021
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants