amplify-js
amplify-js copied to clipboard
Bug with subscription in DataStore
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Categories
api
Environment information
System:
OS: Windows 10 10.0.19044
CPU: (4) x64 AMD Ryzen 3 2200G with Radeon Vega Graphics
Memory: 3.09 GB / 6.93 GB
Binaries:
Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
Watchman: 20220410.024423.0 - C:\Users\taZik\AppData\Local\watchman\watchman.EXE
Browsers:
Chrome: 100.0.4896.127
Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.44)
Internet Explorer: 11.0.19041.1566
npmGlobalPackages:
@aws-amplify/cli: 7.6.26
expo-cli: 5.3.0
typescript: 4.6.2
yarn: 1.22.18
Describe the bug
callback function in subscription called 3 times and with empty data in 2 cases
Expected behavior
The subscription should called 1 time and return updated data
Reproduction steps
DataStore.observe(History).subscribe(..,)
Code Snippet
DataStore.observe(History).subscribe(msg => {
console.log(msg)
})
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
Pixel4
Mobile Operating System
Android11
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
@taZik616 could you provide a bit more info on your API usage, and if possible provide a code snippet where you're registering the callback and executing mutation? Are you performing a mutation remotely via AppSync directly, or are you using DataStore locally and listening to callbacks.
DataStore will execute callbacks for local events as well as remote, and in the case of a local update you may not see all fields as well.
I am also experiencing this issue, setting up a subscription to one of my models results in a local callback 3 times: the first callback has the transformed data, the next 2 callbacks have the old version of the data.
Subscription
DataStore.observe(Region).subscribe((msg) => {
console.warn('Incoming > ', msg)
})
Update
const original = await DataStore.query(Region, 'one')
DataStore.save(
Region.copyOf(original, (updated) => {
updated.dateLastUpdated = `${Date.now()}`
console.log('Finished update', updated.text)
}),
)

When you say "the next 2 callbacks have the old version of the data" you mean that the message shows the original values before updating the record?
I was able to reproduce multiple subscription messages, but they contain all of the updated values for me.
Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.
Thank you!