amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Bug with subscription in DataStore

Open gendalf-thug opened this issue 3 years ago • 3 comments
trafficstars

Before opening, please confirm:

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

gendalf-thug avatar Apr 20 '22 18:04 gendalf-thug

@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.

alharris-at avatar Jun 01 '22 18:06 alharris-at

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)
  }),
  )

screenshot 2022-06-08 at 20 41 25

aaronfay avatar Jun 09 '22 03:06 aaronfay

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.

dpilch avatar Jun 24 '22 19:06 dpilch

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!

chrisbonifacio avatar Aug 31 '22 15:08 chrisbonifacio