Open johnmacabed opened 5 months ago
Hi @johnmacabed 👋 thanks for raising this issue.
There have been similar issues in the past regarding consecutive saves. The workaround of adding a timeout in between calls is also consistent with addressing those issues.
I'll mark this as a bug for the team to investigate further. Thank you for the reproduction steps.
@johnmacabed can you share your schema, and explain your use-case in more detail (e.g. are you depending on the _version
field for some sort of validation, etc)? Is there an unintended side effect with regards to the _version
not being updated before the second call?
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
DataStore
Amplify Version
v6
Amplify Categories
storage
Backend
Amplify CLI
Environment information
Describe the bug
I query my UserLevel model and get the latest data, I update via copyOf then save it. I then do the same with my IndividualData model right after, and its sending the _version that the UserLevel call received in its response. I checked the params before the call and its the correct _version, but the actual call in that gets sent out has the version of the previous model. It will send the right _version if i put a timeout between calls, so it seems to be a race condition. I also went digging in the Datastore lib save function and see awaits in a for loop, awaits are not respected in for loops.
Expected behavior
I expect that my second call to Datastore.save() will have the version that i am sending or calculate it correctly for itself.
Reproduction steps
Call two successive DataStore.save() functions.
Code Snippet
Log output
if i put a timeout of 500ms between them it works fine.
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
After finding https://github.com/aws-amplify/amplify-js/pull/7354, I am suspecting the _version in the previous requests response overwrites the mutation in the outbox because it has the same id as the previous request, even though its another model and different request. If this is the case, I will have to prevent multiple requests with same id parameter. No response