-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Increment on embedded document does not return entire document after Parse.Object.save() #6899
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
Comments
I am not sure if it is a bug since it is returning, and only returning, the key that was changed and all other elements continue the same. Do you see any bad behavior in the client side because of this? |
@davimacedo Right, for a straight up save, that is what I would expect. You can see in the log that is happening properly... and as you say, expected. However, this is a slightly different situation. This is the situation where the instance has already fetched the object. So the complete object is available. In that case, when you increment a regular property (answeredIncorrectlyCount in the log) and then Parse.Object.save() you get back all of the properties again. I probably should have included the following sudo code
Does that make the situation a little more clear? |
This maybe an issue with how the JS SDK handles object states internally. I’ll have to look into it, I believe there is a test case for this. I was the one that added increment on nested / embedded documents to the SDK although it wasn’t recommended. |
Although it may only be somewhat related, I'll reference #6687 |
I had the same thought when filing this... do I put it on this repo or the JS SDK repo?
I am very glad you did add this functionality. Mongo supports it natively so I was pleased to see it was exposed by Parse. Also nice to hear there may be a test already. I will take a look as well, but if you have a particular place in mind @dplewis , please point me in the right direction. |
@dplewis I THINK the issue is with the _handleSaveResponse method. At this point, the this variable has the proper values of choiceStats (with all embedded values). I think there are 2 issues. First, line 541 results in a false condition because the '.' based attr is NOT found in response. Basically it doesn't know how to parse out the embedded document property element. As a result it adds this 'new' attribute property to changes when it shouldn't. For our particular case, I think we would have to be looking at a sliced version of the attr variable.
to avoid adding the embedded document update to changes. That isn't 'fatal' though, it just tacks on some extra properties to the object. I think the core issue is within
Following a little further down the chain, it appears everything is correct (save for some extra props in changes) at I think the real issue is that for the increment operation to work like everything else, it needs to return the ENTIRE document from which it made the internal increment. Otherwise, you run into the above issue with the inability to Is it possible to adjust that increment operation accordingly? I didn't quite see where that was taking place. |
You can checkout this PR and the conversation. parse-community/Parse-SDK-JS#729 Feel free to write a new test case to replicate your issue. On the server you can look at the RestWrite.js, I think that returns the object |
@dplewis Done... though I am a little stymied by the result. My change does fix the issue when I use it in my project... but it doesn't result in passing tests. I think I am missing something simple. As an aside, I think there are a couple ways to approach this. It may be better to adjust what is returned when the save() happens. If it returned the full updated embedded document, that would almost fix everything with little change. That said, there is an issue where some props are added to the changes element that shouldn't be. |
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. |
New Issue Checklist
Issue Description
Although not explicitly stated in the documentation, one is able to increment values in an embedded document. For example, with
Metric
as our class with the following schemaOne can call
metric.increment('stats.first')
This appropriately increments the value at
Metric.stats.first
Where the bug shows up is when you save the
metric
. The returned / updated value ofmetric
does NOT include the rest of the properties in the embedded document stats. Even if you had fetched the ENTIRE object prior to the increment command, the save will ONLY return the updated info of the embedded document property.Steps to reproduce
Actual Outcome
Expected Outcome
My guess is that inside the source code, we are not merging the updated value with a 'spread' version of the prior object properly. This despite having all of the values prior to the increment which is confirmed in the verbose log AND using VS Code to debug in real time.
Environment
Server
Database
Client
Logs
The text was updated successfully, but these errors were encountered: