Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

ParseObject.get has side effects for pending operations on nested fields

Open mstniy opened this issue 4 years ago • 2 comments

New Issue Checklist

Issue Description

Pending operations on nested fields of depth at least two get re-done for every call to .get()

Steps to reproduce

  1. Create an object with a double-nested integer field:
const obj = new TestObject();
obj.set('objectField', { foo: { bar: 5 } });
  1. Save the object to create it:
await obj.save();
  1. Increment the nested field:
obj.increment('objectField.foo.bar', 15);
  1. Read its value twice:
assert.equal(obj.get('objectField').foo.bar, 20);
assert.equal(obj.get('objectField').foo.bar, 20);

Actual Outcome

The first assert succeeds, the second fails with 35 != 20 Note that without the call to .save(), even the first assert fails with 15 != 20, which might be a separate issue.

Expected Outcome

Both asserts should succeed

Environment

Server

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

Database

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

Client

  • Parse JS SDK version: master as of 14 May

Logs

mstniy avatar May 14 '21 19:05 mstniy

These lines should probably be doing a deep-copy. Feels like we should also remove line 138 and the spread at line 139.

mstniy avatar May 14 '21 19:05 mstniy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 21 '21 05:07 stale[bot]

Fixed after #1451

mstniy avatar May 01 '24 21:05 mstniy