Open mstniy opened 2 years ago
Nice find! Do you want to open a PR? This may well be a Parse JS SDK issue rather than a Parse Server issue, if the SDK doesn't handle this set / unset properly. Did you look at what the SDK sends to the server?
I have verified that the SDK sends a malformed request to the server, so this is an SDK issue.
Great, would you want to open a PR with a failing test?
@mstniy Do you have any more infos on this issue? Otherwise I'll transfer it to the Parse JS SDK.
I am afraid not, @mtrezza . Feel free to transfer the issue. We ended up working around it.
Looking at this for a moment, not sure there isn't more related issues.
Trying to just add data.b
(not unsetting) and trying to get it after removes locally the previous value. It doesn't merge the ops locally.
I didn't realize dot notation was even supported on set/get, but there seem to be a lot of issues with it.
Steps to reproduce const myObj = new Parse.Object('MyClass'); await myObj.save(null, {useMasterKey: true}); myObj.set('data', {a: 5}); myObj.unset('data.a'); await myObj.save(null, {useMasterKey: true}); console.log('a');
Above code gives internal server error because of conflict.
MY Solution: The error you're encountering is due to conflicting update operations in MongoDB. Specifically, you're trying to unset a nested field (data.a) after modifying the object, which is causing MongoDB to throw the ConflictingUpdateOperators error because it doesn't allow multiple operations that affect the same path in a single update.
Here's how you can resolve it:
Solution 1: Use Separate Saves Instead of updating and unsetting in the same save operation, separate them into distinct saves to avoid conflicting update operators.
Explanation Initial Save: The object is first saved with no changes. Set and Save: The object’s data field is set with the value { a: 5 } and saved. Unset and Save: The nested field data.a is then unset and saved again in a separate operation.
@mtrezza Please review it once:)
Specifically, you're trying to unset a nested field (data.a) after modifying the object, which is causing MongoDB to throw the ConflictingUpdateOperators error because it doesn't allow multiple operations that affect the same path in a single update.
@harshbhar0629 Good analysis, I think we may have 2 issues here:
ConflictingUpdateOperators
, then the server should not have an internal error, but the error should be caught, logged with details, and a general Parse Error should be returned, without any specific internal error details for security reasons.Would you want to write a fix? You could start with a PR that contains the code example you posted above to demonstrate the issue.
I will try to fix that issue Sir:)
@harshbhar0629 I didn't notice but we already have an open PR with https://github.com/parse-community/Parse-SDK-JS/pull/2117. Please see the discussion there and feel free to pick up from there, as the PR seems to have gone stale.
New Issue Checklist
Issue Description
Setting a subdocument entirely, followed by an
unset
of a nested field causes an internal server error while the object is being saved, if the object existed beforehand.Steps to reproduce
Actual Outcome
Expected Outcome
The object should be saved to the database with data =
{}
Environment
Server
5.3.0
ubuntu 20.04
local
Database
MongoDB
5.0.13
local
Client
parse dashboard
4.1.4
Logs