Amplify-android: [Flutter Support] Failing to sync down a delete mutation for connected model

Created on 30 Nov 2020  路  2Comments  路  Source: aws-amplify/amplify-android

In a typical Blog & Post schema, when I delete a post instance (belonging to a Blog) from let's say a iOS device, I get an error while (android DataStore is) querying for that item in the local datastore before deleting from it.

android.database.sqlite.SQLiteException: ambiguous column name: id (code 1 SQLITE_ERROR): , while compiling: SELECT `Post`.`id` AS `Post_id`, `Post`.`created` AS `Post_created`, `Post`.`rating` AS `Post_rating`, `Post`.`title` AS `Post_title`, `Post`.`blogID` AS `Post_blogID`, `Blog`.`id` AS `Blog_id`, `Blog`.`name` AS `Blog_name` FROM `Post` LEFT JOIN `Blog` ON `Post`.`blogID`=`Blog`.`id` WHERE id = ? LIMIT ? OFFSET ?;
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:986)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:593)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
        at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1443)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1382)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.getQueryAllCursor(SQLiteStorageAdapter.java:825)
at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$5$SQLiteStorageAdapter(SQLiteStorageAdapter.java:406)
at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$YrR7B1Rj3JmC_omOKlzMTn0U5hM.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:919)
W/System.err: android.database.sqlite.SQLiteException: ambiguous column name: id (code 1 SQLITE_ERROR): , while compiling: SELECT `Post`.`id` AS `Post_id`, `Post`.`created` AS `Post_created`, `Post`.`rating` AS `Post_rating`, `Post`.`title` AS `Post_title`, `Post`.`blogID` AS `Post_blogID`, `Blog`.`id` AS `Blog_id`, `Blog`.`name` AS `Blog_name` FROM `Post` LEFT JOIN `Blog` ON `Post`.`blogID`=`Blog`.`id` WHERE id = ? LIMIT ? OFFSET ?;
at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$5$SQLiteStorageAdapter(SQLiteStorageAdapter.java:451)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$YrR7B1Rj3JmC_omOKlzMTn0U5hM.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:919)

The three variables were

0 = "<a UUId>"
1 = "1"
2 = "0"

Non connected models (such as blog's) get deleted from android DataStore fine.

Bug DataStore Flutter

All 2 comments

Hi @Amplifiyer, let me make sure I understand your steps.

  1. Your schema includes a Blog and a Post, where a blog "has many" posts, and each post "belongs to" a blog.
  2. You create a Blog and a Post remotely, and they sync to two clients (an iOS client and an Android client), both.
  3. You try to initiate a delete from an iOS device. This deletes the content on the iOS device. The mutation propagates to AppSync.
  4. AppSync notifies all clients of a deletion mutation over the subscription.
  5. While processing the deletion, the Android DataStore checks to see if that item is in the local DataStore, before trying to delete it.
  6. The query fails and emits the stack trace below.
android.database.sqlite.SQLiteException: ambiguous column name: id (code 1 SQLITE_ERROR): , while compiling: SELECT `Post`.`id` AS `Post_id`, `Post`.`created` AS `Post_created`, `Post`.`rating` AS `Post_rating`, `Post`.`title` AS `Post_title`, `Post`.`blogID` AS `Post_blogID`, `Blog`.`id` AS `Blog_id`, `Blog`.`name` AS `Blog_name` FROM `Post` LEFT JOIN `Blog` ON `Post`.`blogID`=`Blog`.`id` WHERE id = ? LIMIT ? OFFSET ?;

@jamesonwilliams You are absolutely right. For step #2 I'm creating Blog and Post instances from either android or iOS device and made sure that they are synced to android devices before I tried to delete them.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Diegolotr99 picture Diegolotr99  路  7Comments

chiragmittal19 picture chiragmittal19  路  5Comments

tomasfelder picture tomasfelder  路  5Comments

jamesonwilliams picture jamesonwilliams  路  6Comments

Scarlett13 picture Scarlett13  路  6Comments