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

Error in updating a value

Open YanSen1996 opened this issue 3 years ago • 9 comments

Hi, my app works well last Friday (26 August 2022), but I got this error when trying to update the item in my database on 30 August 2022.

W/amplify:aws-datastore: Failed to publish a local change = PendingMutation{mutatedItem=SerializedModel{id='c2757abf-3472-4998-b038-250e0ced20be', serializedData={isOnJourney=0, endpoint=***, ***, tripID=null, id=c2757abf-3472-4998-b038-250e0ced20be, username=null}, modelName=SBMobileAppDB}, mutationType=UPDATE, mutationId=31d29693-2915-11ed-9c10-e57afba971f0, predicate=MatchAllQueryPredicate}
    DataStoreException{message=Wanted 1 metadata for item with id = c2757abf-3472-4998-b038-250e0ced20be, but had 0., cause=null, recoverySuggestion=This is likely a bug. please report to AWS.}
        at com.amplifyframework.datastore.syncengine.VersionRepository.extractVersion(VersionRepository.java:91)
        at com.amplifyframework.datastore.syncengine.VersionRepository.lambda$null$0$VersionRepository(VersionRepository.java:64)
        at com.amplifyframework.datastore.syncengine.VersionRepository$$ExternalSyntheticLambda0.accept(Unknown Source:8)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$4$SQLiteStorageAdapter(SQLiteStorageAdapter.java:406)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter$$ExternalSyntheticLambda6.run(Unknown Source:10)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

I've already enabled the conflict detection (with Auto Merge chosen). Could you please kindly let me know what I could do about this problem?

YanSen1996 avatar Aug 31 '22 10:08 YanSen1996

This just began happening to me as well on a production environment.

Here's what I get from my Google Play Console crash stack trace

Exception j.c.a.c.f:
  at io.reactivex.rxjava3.plugins.RxJavaPlugins.onError (RxJavaPlugins.java)
  at io.reactivex.rxjava3.internal.operators.single.SingleCreate$Emitter.onError (SingleCreate.java)
  at com.amplifyframework.datastore.syncengine.VersionRepository.lambda$null$0 (VersionRepository.java)
  at com.amplifyframework.datastore.syncengine.VersionRepository.lambda$null$0$VersionRepository (VersionRepository.java)
  at com.amplifyframework.datastore.syncengine.-$$Lambda$VersionRepository$Kmuu7iZPxyGP2VIH1c1HFJFJDKw.accept (-.java)
  at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$4 (SQLiteStorageAdapter.java)
  at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$4$SQLiteStorageAdapter (SQLiteStorageAdapter.java)
  at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$CxFeClFgMnCdkUir6dsRxPfXmiA.run (-.java)
  at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:462)
  at java.util.concurrent.FutureTask.run (FutureTask.java:266)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:920)
Caused by : DataStoreException{message=Wanted 1 metadata for item with id = REMOVED-FOR-PRIVACY-PURPOSES, but had 0., cause=null, recoverySuggestion=This is likely a bug. please report to AWS.}
  at com.amplifyframework.datastore.syncengine.VersionRepository.extractVersion (VersionRepository.java)
  at com.amplifyframework.datastore.syncengine.VersionRepository.lambda$null$0 (VersionRepository.java)

djsjr avatar Sep 02 '22 04:09 djsjr

Same here

pcanas avatar Sep 02 '22 13:09 pcanas

When this error happens, the app crashes. I had many users report crashes every time they used the app and had to downgrade to an older version to fix the issue for my users. Any progress on this?

djsjr avatar Sep 05 '22 03:09 djsjr

@YanSen1996 Sorry to hear that you are experiencing this error, could you please share your schema and the code snippet for update mutation?

poojamat avatar Sep 05 '22 03:09 poojamat

@YanSen1996 Sorry to hear that you are experiencing this error, could you please share your schema and the code snippet for update mutation?

Hi, please kindly find the schema and code for the item updating below.

Schema image

Code

// define
public void update(String journeyState, String endpoint) {
        SBMobileAppDB item = SBMobileAppDB.builder()
		.id("c2757abf-3472-4998-b038-250e0ced20be")
		.isOnJourney(journeyState)
		.endpoint(endpoint)
		.build();
	Amplify.DataStore.save(
		item,
		success -> Log.i("Amplify", "Saved item: " + success.item().getId()),
		error -> Log.e("Amplify", "Could not save item to DataStore", error)
	);
}

// call
update("0", String.valueOf(lat) + ", " + String.valueOf(lon));

YanSen1996 avatar Sep 07 '22 15:09 YanSen1996

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Sep 07 '22 15:09 github-actions[bot]

@poojamat just to make sure that the notification is sent since the issue was closed accidentally

pcanas avatar Sep 07 '22 19:09 pcanas

@YanSen1996 I was not able to reproduce this error with the above schema and update command. What version of amplify library are you using? Are the mutations just failing for this model? Does the sync complete successfully and subscriptions are established successfully?

poojamat avatar Sep 08 '22 21:09 poojamat

@poojamat This error occurs for me when a user who's device has a synced local database via datastore gets updated to the latest version of datastore. (I am using flutter, so I can only report those version numbers, but I am sure you know which Android version is contained inside each flutter version.)

For example, if a user has synced datastore and gets upgraded from Flutter Datastore 0.6.1 to 0.6.8, their app will crash within seconds of opening every time.

If a user clears Datastore, upgrades to 0.6.8, and then syncs, there is no crash.

If a user remans on 0.6.1 there is no crash.

It seems obvious that there's a compatibility issue with the tables when upgrading. In the past, there was never a need to clear and re-sync between versions.

Additionally, I found while testing this on my simulator that along with the initial error message, I get this no such column: __typename error:

DataStoreException{message=Initial cloud sync failed for User., cause=DataStoreException{message=Error in saving the
model: ModelMetadata[primaryKey =User|282e7103-ccf8-4aa0-bf4f-6fb72f387647],
cause=android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling:
UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE
`ModelMetadata`.`id` = ?;, recoverySuggestion=See attached exception for details.}, recoverySuggestion=Check your
internet connection.}

I'll post the entire error here since it may help you

2022-09-29 16:41:58.916 14639-14935/? E/AndroidRuntime: FATAL EXCEPTION: pool-21-thread-18
    Process: com.DOMAIN.APP_NAME, PID: XXXXX
    io.reactivex.rxjava3.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | DataStoreException{message=Wanted 1 metadata for item with id = 282e7103-ccf8-4aa0-bf4f-6fb72f387647, but had 0., cause=null, recoverySuggestion=This is likely a bug. please report to AWS.}
        at io.reactivex.rxjava3.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
        at io.reactivex.rxjava3.internal.operators.single.SingleCreate$Emitter.onError(SingleCreate.java:82)
        at com.amplifyframework.datastore.syncengine.VersionRepository.lambda$null$0$VersionRepository(VersionRepository.java:66)
2022-09-29 16:41:58.916 14639-14936/? E/amplify:flutter:datastore: DataStoreException{message=Initial cloud sync failed for User., cause=DataStoreException{message=Error in saving the model: ModelMetadata[primaryKey =User|282e7103-ccf8-4aa0-bf4f-6fb72f387647], cause=android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling: UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE `ModelMetadata`.`id` = ?;, recoverySuggestion=See attached exception for details.}, recoverySuggestion=Check your internet connection.}
2022-09-29 16:41:58.916 14639-14767/? E/amplify:aws-datastore: Failure encountered while attempting to start API sync.
    DataStoreException{message=Initial sync during DataStore initialization failed., cause=java.lang.RuntimeException: DataStoreException{message=Error in saving the model: ModelMetadata[primaryKey =User|282e7103-ccf8-4aa0-bf4f-6fb72f387647], cause=android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling: UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE `ModelMetadata`.`id` = ?;, recoverySuggestion=See attached exception for details.}, recoverySuggestion=There is a possibility that there is a bug if this error persists. Please take a look at 
    https://github.com/aws-amplify/amplify-android/issues to see if there are any existing issues that 
    match your scenario, and file an issue with the details of the bug if there isn't.}
        at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$3$Orchestrator(Orchestrator.java:322)
        at com.amplifyframework.datastore.syncengine.-$$Lambda$Orchestrator$PVk58tU0K8ndPJYnH_tRmf4RGwE.subscribe(Unknown Source:2)
        at io.reactivex.rxjava3.internal.operators.completable.CompletableCreate.subscribeActual(CompletableCreate.java:40)
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
        at io.reactivex.rxjava3.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64)
        at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
     Caused by: java.lang.RuntimeException: DataStoreException{message=Error in saving the model: ModelMetadata[primaryKey =User|282e7103-ccf8-4aa0-bf4f-6fb72f387647], cause=android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling: UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE `ModelMetadata`.`id` = ?;, recoverySuggestion=See attached exception for details.}
        at io.reactivex.rxjava3.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:46)
        at io.reactivex.rxjava3.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:94)
        at io.reactivex.rxjava3.core.Completable.blockingAwait(Completable.java:1461)
        at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$3$Orchestrator(Orchestrator.java:318)
        at com.amplifyframework.datastore.syncengine.-$$Lambda$Orchestrator$PVk58tU0K8ndPJYnH_tRmf4RGwE.subscribe(Unknown Source:2) 
        at io.reactivex.rxjava3.internal.operators.completable.CompletableCreate.subscribeActual(CompletableCreate.java:40) 
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850) 
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51) 
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850) 
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51) 
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850) 
        at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51) 
        at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850) 
        at io.reactivex.rxjava3.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64) 
        at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614) 
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65) 
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:920) 
2022-09-29 16:41:58.916 14639-14767/? E/amplify:aws-datastore: Caused by: DataStoreException{message=Error in saving the model: ModelMetadata[primaryKey =User|282e7103-ccf8-4aa0-bf4f-6fb72f387647], cause=android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling: UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE `ModelMetadata`.`id` = ?;, recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:382)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$0Q4t2Se5oVsIb4pxkwWPcTH3ADs.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        	... 3 more
     Caused by: android.database.sqlite.SQLiteException: no such column: __typename (code 1 SQLITE_ERROR): , while compiling: UPDATE `ModelMetadata` SET `id` = ?, `__typename` = ?, `_deleted` = ?, `_lastChangedAt` = ?, `_version` = ? WHERE `ModelMetadata`.`id` = ?;
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1047)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:654)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:62)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:34)
        at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1224)
        at com.amplifyframework.datastore.storage.sqlite.SQLCommandProcessor.execute(SQLCommandProcessor.java:73)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.writeData(SQLiteStorageAdapter.java:773)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:365)
        	... 6 more

I am going to post this as a new issue in amplify-flutter as well

djsjr avatar Sep 29 '22 21:09 djsjr

Thanks for the stack trace @djsjr, more customers are seeing this over in https://github.com/aws-amplify/amplify-android/issues/2066

If a user clears Datastore, upgrades to 0.6.8, and then syncs, there is no crash.

If a user remans on 0.6.1 there is no crash.

It seems obvious that there's a compatibility issue with the tables when upgrading. In the past, there was never a need to clear and re-sync between versions.

This looks to be in-line with what i think the repro steps are when directly developing an Android app (v1.34.4 to v1.37.5 rather than Flutter versions). We will have to investigate further

lawmicha avatar Nov 02 '22 15:11 lawmicha

duplicate issue #2066 2066

AnilMaktala avatar Dec 21 '22 19:12 AnilMaktala

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Dec 21 '22 19:12 github-actions[bot]