Repository: aws-amplify/amplify-flutter

Issue #3113: observeQuery isSynced value is incorrect after DataStore.clear()
Created: 2023-05-26T20:30:56Z
Description
The value for isSynced returned from observeQuery will be true after calling DataStore.clear() even while a new sync is in progress. isSynced should probably reset to false.
Categories

 Analytics
 API (REST)
 API (GraphQL)
 Auth
 Authenticator
 DataStore
 Storage

Steps to Reproduce
No response
Screenshots
No response
Platforms

 iOS
 Android
 Web
 macOS
 Windows
 Linux

Flutter Version
n/a
Amplify Flutter Version
1.1.0
Deployment Method
Amplify CLI
Schema
No response

Duplicate issue #4963: Datastore query returns empty list even when isSynced: true in observeQuery snapshot.
Created: 2024-06-03T17:26:46Z
Description
Datastore starts syncing when the app is freshly installed or when it is accessed for the first time after Amplify.DataStore.clear() when user signs out. This issue has already been filed before. As mentioned in this comment, I am using observeQuery to check if the datastore has finished syncing and then only start querying data.
final QuerySnapshot<User> snapshot = await Amplify.DataStore.observeQuery(
  User.classType,
).firstWhere((snapshot) => snapshot.isSynced);
But even when isSynced is true, the snapshot.items is empty. But after hot-restarting the app, relaunching the app or a slight delay (debugging using breakpoints) a non-empty list is returned.
Categories

 Analytics
 API (REST)
 API (GraphQL)
 Auth
 Authenticator
 DataStore
 Notifications (Push)
 Storage

Steps to Reproduce

Make a fresh new install of the Flutter application or clear DataStore on log out and log back in.
Wait for the datastore to get synced using observeQuery.

 await Amplify.DataStore.observeQuery(
  User.classType,
).firstWhere((snapshot) => snapshot.isSynced)

Check snapshot.items or use Amplify.query  after the snapshot is returned after snapshot.isSynced is true.

Screenshots
No response
Platforms

 iOS
 Android
 Web
 macOS
 Windows
 Linux

Flutter Version
3.22.0
Amplify Flutter Version
2.0.0
Deployment Method
Amplify CLI
Schema
# This "input" configures a global authorization rule to enable public access to
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules
input AMPLIFY {
  globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type User @model {
  id: String!
  name: String!
  email: String!
  phone: String!
  licenseNo: String!
  brokerAgencyName: String!
  profilePic: String
  contracts: [Contract] @hasMany
}

type Contract @model {
  id: ID!
  mlsID: String!
  propertyAddress: String!
  type: ContractType!
  status: ContractStatus!
  broker: User! @belongsTo
  buyers: [Buyer] @hasMany
}

type Buyer @model {
  id: ID!
  name: String!
  email: String!
  phone: String!
  contract: Contract! @belongsTo
  signature: String
  ipAddress: String
  timestamp: AWSDateTime
}

enum Usertype {
  broker
}

enum ContractType {
  showing
}

enum ContractStatus {
  draft
  sent
  signed
}

Closing comment (2024-06-03T18:49:55Z): @agent515 - Thanks for opening the issue and providing repro steps. Does this only occur after calling Datastore.clear() or Datastore.stop()? If so, I think this may be a duplicate of #3113. Can you take a look at that issue and let me know if you do not think this is a duplicate? Thanks