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

fix: Setting and unsetting property without saving `Parse.Object` causes server error

Open mortenmo opened this issue 4 months ago • 15 comments

Pull Request

Issue

Closes: https://github.com/parse-community/Parse-SDK-JS/issues/1798

Approach

On the path of making my app work well offline, this was one more blocker.

The problem is that if you set a parent object o.set('data', {a: b, b: 3}) and then set or unset anything on data (example: o.unset('data.a') without saving between (or save failed for no connection), you get a server error on save(). 1798 indicates this needs to be fixed on client. What fails seems to be mongo doesn't support setting an object and then sub-properties in the same call which is what the server attempts to do in this case.

This fix merges Ops if a "parent" Op exists locally and is not changed and applies the new Op to that parent. In the end this means that when sent to server it wont create the issue above and succeed even if subproperties were set/unset/incremented as a part of local operation before save.

Small(?) change to ParseObject.set with calling validPendingParentOp that if the current Op attribute has dots (.) it will look for pending parent Operations. If one is found, applyOpToParent is called taking the new Op and applying the change to it locally. Put these new functions in ParseOp, but that might not be the best place for them (maybe ObjectStateController?).

Tasks

  • [X] Add tests
  • [x] Add test to validate server can save properly now

mortenmo avatar Apr 29 '24 15:04 mortenmo