-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Datastore update does not increment version correctly after second update #9942
Comments
I have the same issue and assumed I didn't know what I was doing. To get updates to work I had to requery the record, even if it already had it in state, then mutate that freshly queried data to save. Still very interested in the solve for this generally. All I should need to send is the ID and the updated value and it should work. |
@jedgrant Yes, I eventually came across this workaround too. I ended up fetching and saving the data again within datastore.observe. |
@jedgrant @djcade32 are you both also doing text input for your React UI? You shouldn't need to ever re-query for the latest version, this should happen automatically by DataStore as you can see in this example: https://docs.amplify.aws/lib/datastore/examples/q/platform/js/#example-application I have a suspicion that this may be due to text input and/debouncing of some sort that we might need to document better but I'm trying to understand the why on this happening first. Also @jedgrant are you using React Native as well? |
@undefobj - I am focused just on React JS at the moment. I could also very well be doing it wrong. I am attempting to DataStore.save() when a textarea changes (after a short delay of user inactivity). This word processor. I am not using subscribe or observe as seen in that example. I have a function in the component that gets called onChange that executes DataStore.save like this https://docs.amplify.aws/lib/datastore/data-access/q/platform/js/#create-and-update I don't see how the example you linked lets me save iteratively at all to be honest. Even the example in the docs has you query for the original before using that to update. I know the value I want to change and the id of the thing it's on, but that doesn't seem to be enough. |
Seems related:
The PR has comments indicating some discussion is needed. It probably makes sense for us to discuss these together, @manueliglesias + @dpilch. |
I'll take a look and add to the research if it is related. |
We've updated our docs to provide a warning for working with stale data, and have added a code sample as well (available here https://docs.amplify.aws/lib/datastore/data-access/q/platform/js/#create-and-update). We are also tracking a followup item to emit a warning in the console for users who encounter this state in the future (tracking separately). Thank you for raising this issue! |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, DataStore
Amplify Categories
Environment information
Describe the bug
I am new to using Amplify. So I am hoping this is an easy fix. I am having problems with updating the Aws-Amplify database. This is my schema.graphql
I can save a User to the database just fine but when I try to update that same user more than twice, datastore does not perform the update.
I did some further digging by observing the User model and found out that datastore is incrementing the version with the updated values correctly for the first update. But when I try to attempt a second update it decreases the version for the new User value but then increments it again with the previous value. So it looks like the database never got updated. I created console log outputs to show the process. I provided the logs below hopefully this helps illustrate the problem. I am changing and updating the age field.
Expected behavior
I expect the database to update and show the correct value. I expect the versions to increment correctly when using the datastore.
Reproduction steps
Code Snippet
Log output
When I turn on debug, this is what I get.
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: