#✅ - Datastore: Datastore.clear() not working

6 messages · Page 1 of 1 (latest)

woven quarry
#

Hi Peeps,

I've experiencing an issue where DataStore.clear() does not seem to complete successfully in react-native. Even after calling await DataStore.clear(), I still encounter the following error when trying to observe data:

Error: DataStoreStateError: Tried to execute DataStore.observe() while DataStore was "Clearing".
This can only be done while DataStore is "Started" or "Stopped". To remedy:
Ensure all calls to stop() and clear() have completed first.
If this is not possible, retry the operation until it succeeds., js engine: hermes

Steps We Have Taken to Resolve the Issue:

  1. Awaiting DataStore.clear() Before Restarting
  2. Implementing a Retry Mechanism
  3. Using DataStore.stop() Before Clearing

DataStore.clear() appears to hang in the "Clearing" state indefinitely, preventing any further DataStore operations.
Is there any known issue with DataStore.clear() not completing? Are there additional steps we should take to ensure clear() fully executes before restarting DataStore?

Kindly assist

Thanks.

buoyant oracle
#

Hi @woven quarry there have been a few issues similar to this opened on the amplify-js repo. Have you had a chance to take a look through those?

Here's an example that might help:
https://github.com/aws-amplify/amplify-js/issues/12359

GitHub

Before opening, please confirm: I have searched for duplicate or closed issues and discussions. I have read the guide for submitting bug reports. I have done my best to include a minimal, self-cont...

woven quarry
buoyant oracle
#

Sorry to hear that 🙁 These kinds of issues are very hard to troubleshoot without the actual app and logic to sift through.

A few questions though, in case it helps:

  1. Is this a new app or existing one? I ask because if it's new, then perhaps there are other solutions that can help unblock you and potentially save you some troublesome tech debt.

  2. Are you using it because you need the offline capabilities? If not, I would recommend ditching it altogether unless you absolutely need the sync mechanism.

For developers new to Amplify or just starting a new project with Gen 2, we are recommending customers use a third party alternative like TanStack Query for offline use cases:
https://tanstack.com/query/latest/docs/framework/react/plugins/createAsyncStoragePersister

It should be compatible with Gen 1 Amplify apps as well. If the app is an existing one where refactoring is not an option, I would recommend opening an issue on github:
https://github.com/aws-amplify/amplify-js/issues

However, to set the right expectations, the support may still be limited because while we still support and are looking to fix bugs in Gen 1, DataStore is an offering that currently has no plans of being supported in Gen 2 so please keep that in mind.

If you are able to provide enough details about the app and business logic around datastore, perhaps we can still help you figure out why the issue is occurring.

Installation This utility comes as a separate package and is available under the '@tanstack/query-async-storage-persister' import. bash npm install @tanstack/query-async-storage-persister @tanstack/re...

GitHub

A declarative JavaScript library for application development using cloud services. - Issues · aws-amplify/amplify-js

woven quarry
hearty lodgeBOT
#

✅ - Datastore: Datastore.clear() not working