Skip to content

Set Objects in afterFind and afterLiveQueryEvent triggers #7310

Closed

Description

@dblythy

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

Activity

  1. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    on Apr 4, 2021
  2. mtrezza commented on Apr 4, 2021

    @mtrezza
    Member

    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?
  3. dblythy commented on Apr 4, 2021

    @dblythy
    MemberAuthor

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

  4. mtrezza commented on Apr 4, 2021

    @mtrezza
    Member

    Thanks, I classified this as bug with severity S3:

  5. parseplatformorg commented on Nov 1, 2021

    @parseplatformorg
    Contributor

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

  6. parseplatformorg commented on Mar 14, 2022

    @parseplatformorg
    Contributor

    🎉 This change has been released in version 5.0.0

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

    state:releasedReleased as stable versionstate:released-betaReleased as beta versiontype: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