question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

observeQuery does not return an updated items array when a model has been mutated

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

DataStore

Amplify Categories

Not applicable

Environment information

  System:
    OS: macOS 12.0.1
    CPU: (6) x64 Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
    Memory: 15.88 GB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.1 - /usr/local/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Chrome: 96.0.4664.93
    Firefox: 94.0.2
    Safari: 15.1
  npmPackages:
    @sermonary/components: ^0.3.29 => 0.3.29
    @sermonary/theme: ^0.3.29 => 0.3.29
    @types/node: ^12.0.0 => 12.20.15
  npmGlobalPackages:
    corepack: 0.10.0
    npm: 8.1.2

Describe the bug

The ObserveQuery API is not returning the updated items when a single model has been mutated. For example, if I am querying and subscribing to model updates like DataStore.observeQuery(Sermon), new items are only emitted for CREATE and DELETE. Updated items are not being emitted when updating a single model in the list, and thus causes my query to be stale and does not reflect what is actually in the DataStore or in the DB.

Expected behavior

I would expect any change to a model to emit a message and cause observeQuery to return a new array of items with the updated model in the response.

Reproduction steps

  1. Observe a model query with DataStore.observeQuery()
  2. Perform a mutation with DataStore.save() on a model that currently exists and was returned by the observeQuery method.
  3. Note that the items are not updated from DataStore.observeQuery()

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wcole1-godaddycommented, Dec 13, 2021
await DataStore.save(
            Sermon.copyOf(sermon, (updated) => {
              updated.title = newSermon?.title;
              updated.bigIdea = newSermon?.bigIdea;
              updated.referenceVerses = newSermon?.referenceVerses;
              updated.seriesId = seriesId;
              updated.blocks = newSermon?.blocks;
            }),
          );
DataStore.observeQuery(Sermon)

It’s a pretty simple handler to update a Sermon model on a single sermon view page and then going back to the sermon list screen, the list hasn’t updated because the Update snapshot hasn’t been sent to observeQuery.

0reactions
github-actions[bot]commented, Dec 21, 2022

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to modify AWS Datastore ObserveQuery model result
I tried to modify mutations, queries and subscriptions model generated by Codegen but no success. Here is the output I am looking for...
Read more >
Announcing custom primary key support for AWS Amplify ...
Today, we are introducing the release of custom primary keys, also known as custom identifiers, for Amplify DataStore to provide additional ...
Read more >
A persistent data structure is one that shares structure with other ...
From the outside, get_x(version1) still returns the same value before and after the update, but the data structure it refers to has been...
Read more >
DataStore - Manipulating data - JavaScript - AWS Amplify Docs
Models in DataStore are immutable. To update a record you must use the copyOf function to apply updates to the item's fields rather...
Read more >
MutationObserver.observe() - Web APIs - MDN Web Docs
A DOM Node (which may be an Element ) within the DOM tree to watch ... DOM mutations should be reported to mutationObserver...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found