aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
246 stars 117 forks source link

Flutter Amplify DataStore SQLiteException no such column User2 #2035

Closed airon-tark closed 1 year ago

airon-tark commented 2 years ago

Description

Having an SQL error on Flutter using DataStore shows fields with the added digit "2" at the end. like "User2.authUser2ID", User2.email AS User_email2, User_updatedAt2, User2 and so on.

My model doesn't have any field with "2" in the end. I checked how it looks on Amplify Studio and in the Dynamo DB table. There are no such fields like "email2", "updateAt2" etc. The app code doesn't have these fields (neither the code nor the generated files). From where do these fields come from?

E/amplify:flutter:datastore(10685): DataStoreException{message=Error in querying the model., cause=DataStoreException{message=Invalid SQL statement: SELECT `User`.`id` AS `User_id`, `User`.`authUserID` AS `User_authUserID`, `User`.`createdAt` AS `User_createdAt`, `User`.`email` AS `User_email`, `User`.`emailConfirmed` AS `User_emailConfirmed`, `User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, `User`.`updatedAt` AS `User_updatedAt`, `User`.`userAccountInfoId` AS `User_userAccountInfoId`, `User`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId`, `User2`.`id` AS `User_id2`, `User2`.`authUser2ID` AS `User_authUserID2`, `User2`.`createdAt` AS `User_createdAt2`, `User2`.`email` AS `User_email2`, `User2`.`emailConfirmed` AS `User_emailConfirmed2`, `User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, `User2`.`updatedAt` AS `User_updatedAt2`, `User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, `User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, `Wristband`.`id` AS `Wristband_id`, `Wristband`.`createdAt` AS `Wristband_createdAt`, `Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, `Wristband`.`eventID` AS `Wristband_eventID`, `Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, `Wristband`.`pinCode` AS `Wristband_pinCode`, `Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, `Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, `Wristband`.`updatedAt` AS `Wristband_updatedAt`, `Wristband`.`uuid` AS `Wristband_uuid`, `Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, `Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, `Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, `Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, `Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, `Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, `Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, `Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, `Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, `Event`.`category` AS `Event_category`, `Event`.`city` AS `Event_city`, `Event`.`country` AS `Event_country`, `Event`.`createdAt` AS `Event_createdAt`, `Event`.`description` AS `Event_description`, `Event`.`finishDate` AS `Event_finishDate`, `Event`.`imageUrl` AS `Event_imageUrl`, `Event`.`latitude` AS `Event_latitude`, `Event`.`longitude` AS `Event_longitude`, `Event`.`name` AS `Event_name`, `Event`.`startDate` AS `Event_startDate`, `Event`.`updatedAt` AS `Event_updatedAt`, `PaymentMethod`.`id` AS `PaymentMethod_id`, `PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, `PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, `PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, `PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, `PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, `PaymentMethod`.`type` AS `PaymentMethod_type`, `PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, `PaymentMethod`.`userID` AS `PaymentMethod_userID`, `PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` WHERE `Wristband`.`wristbandUserID` = ?;, cause=android.database.sqlite.SQLiteException: no such column: User2.authUser2ID (code 1 SQLITE_ERROR): , while compiling: SELECT `User`.`id` AS `User_id`, `User`.`authUserID` AS `User_authUserID`, `User`.`createdAt` AS `User_createdAt`, `User`.`email` AS `User_email`, `User`.`emailConfirmed` AS `User_emailConfirmed`, `User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, `User`.`updatedAt` AS `User_updatedAt`, `User`.`userAccountInfoId` AS `User_userAccountInfoId`,
E/amplify:flutter:datastore(10685):  `User`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId`, `User2`.`id` AS `User_id2`, `User2`.`authUser2ID` AS `User_authUserID2`, `User2`.`createdAt` AS `User_createdAt2`, `User2`.`email` AS `User_email2`, `User2`.`emailConfirmed` AS `User_emailConfirmed2`, `User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, `User2`.`updatedAt` AS `User_updatedAt2`, `User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, `User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, `Wristband`.`id` AS `Wristband_id`, `Wristband`.`createdAt` AS `Wristband_createdAt`, `Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, `Wristband`.`eventID` AS `Wristband_eventID`, `Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, `Wristband`.`pinCode` AS `Wristband_pinCode`, `Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, `Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, `Wristband`.`updatedAt` AS `Wristband_updatedAt`, `Wristband`.`uuid` AS `Wristband_uuid`, `Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, `Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, `Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, `Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, `Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, `Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, `Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, `Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, `Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, `Event`.`category` AS `Event_category`, `Event`.`city` AS `Event_city`, `Event`.`country` AS `Event_country`, `Event`.`createdAt` AS `Event_createdAt`, `Event`.`description` AS `Event_description`, `Event`.`finishDate` AS `Event_finishDate`, `Event`.`imageUrl` AS `Event_imageUrl`, `Event`.`latitude` AS `Event_latitude`, `Event`.`longitude` AS `Event_longitude`, `Event`.`name` AS `Event_name`, `Event`.`startDate` AS `Event_startDate`, `Event`.`updatedAt` AS `Event_updatedAt`, `PaymentMethod`.`id` AS `PaymentMethod_id`, `PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, `PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, `PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, `PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, `PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, `PaymentMethod`.`type` AS `PaymentMethod_type`, `PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, `PaymentMethod`.`userID` AS `PaymentMethod_userID`, `PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` WHERE `Wristband`.`wristbandUserID` = ?;, recoverySuggestion=There is a possibility that there is a bug if this error persists. Please take a look at 
E/amplify:flutter:datastore(10685): https://github.com/aws-amplify/amplify-android/issues to see if there are any existing issues that 
E/amplify:flutter:datastore(10685): match your scenario, and file an issue with the details of the bug if there isn't.}, recoverySuggestion=See attached exception for details.}
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$5$com-amplifyframework-datastore-storage-sqlite-SQLiteStorageAdapter(SQLiteStorageAdapter.java:450)
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter$$ExternalSyntheticLambda8.run(Unknown Source:10)
E/amplify:flutter:datastore(10685):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
E/amplify:flutter:datastore(10685):     at java.util.concurrent.FutureTask.run(FutureTask.java:264)
E/amplify:flutter:datastore(10685):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
E/amplify:flutter:datastore(10685):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
E/amplify:flutter:datastore(10685):     at java.lang.Thread.run(Thread.java:1012)
E/amplify:flutter:datastore(10685): Caused by: DataStoreException{message=Invalid SQL statement: SELECT `User`.`id` AS `User_id`, `User`.`authUserID` AS `User_authUserID`, `User`.`createdAt` AS `User_createdAt`, `User`.`email` AS `User_email`, `User`.`emailConfirmed` AS `User_emailConfirmed`, `User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, `User`.`updatedAt` AS `User_updatedAt`, `User`.`userAccountInfoId` AS `User_userAccountInfoId`, `User`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId`, `User2`.`id` AS `User_id2`, `User2`.`authUser2ID` AS `User_authUserID2`, `User2`.`createdAt` AS `User_createdAt2`, `User2`.`email` AS `User_email2`, `User2`.`emailConfirmed` AS `User_emailConfirmed2`, `User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, `User2`.`updatedAt` AS `User_updatedAt2`, `User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, `User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, `Wristband`.`id` AS `Wristband_id`, `Wristband`.`createdAt` AS `Wristband_createdAt`, `Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, `Wristband`.`eventID` AS `Wristband_eventID`, `Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, `Wristband`.`pinCode` AS `Wristband_pinCode`, `Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, `Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, `Wristband`.`updatedAt` AS `Wristband_updatedAt`, `Wristband`.`uuid` AS `Wristband_uuid`, `Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, `Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, `Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, `Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, `Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, `Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, `Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, `Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, `Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, `Event`.`category` AS `Event_category`, `Event`.`city` AS `Event_city`, `Event`.`country` AS `Event_country`, `Event`.`createdAt` AS `Event_createdAt`, `Event`.`description` AS `Event_description`, `Event`.`finishDate` AS `Event_finishDate`, `Event`.`imageUrl` AS `Event_imageUrl`, `Event`.`latitude` AS `Event_latitude`, `Event`.`longitude` AS `Event_longitude`, `Event`.`name` AS `Event_name`, `Event`.`startDate` AS `Event_startDate`, `Event`.`updatedAt` AS `Event_updatedAt`, `PaymentMethod`.`id` AS `PaymentMethod_id`, `PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, `PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, `PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, `PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, `PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, `PaymentMethod`.`type` AS `PaymentMethod_type`, `PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, `PaymentMethod`.`userID` AS `PaymentMethod_userID`, `PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` WHERE `Wristband`.`wristbandUserID` = ?;, cause=android.database.sqlite.SQLiteException: no such column: User2.authUser2ID (code 1 SQLITE_ERROR): , while compiling: SELECT `User`.`id` AS `User_id`, `User`.`authUserID` AS `User_authUserID`, `User`.`createdAt` AS `User_createdAt`, `User`.`email` AS `User_email`, `User`.`emailConfirmed` AS `User_emailConfirmed`, `User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, `User`.`updatedAt` AS `User_updatedAt`, `User`.`userAccountInfoId` AS `User_userAccountInfoId`, `User`.`userAutoTopUpConfigId` AS `User_userAutoTop
E/amplify:flutter:datastore(10685): UpConfigId`, `User2`.`id` AS `User_id2`, `User2`.`authUser2ID` AS `User_authUserID2`, `User2`.`createdAt` AS `User_createdAt2`, `User2`.`email` AS `User_email2`, `User2`.`emailConfirmed` AS `User_emailConfirmed2`, `User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, `User2`.`updatedAt` AS `User_updatedAt2`, `User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, `User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, `Wristband`.`id` AS `Wristband_id`, `Wristband`.`createdAt` AS `Wristband_createdAt`, `Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, `Wristband`.`eventID` AS `Wristband_eventID`, `Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, `Wristband`.`pinCode` AS `Wristband_pinCode`, `Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, `Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, `Wristband`.`updatedAt` AS `Wristband_updatedAt`, `Wristband`.`uuid` AS `Wristband_uuid`, `Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, `Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, `Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, `Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, `Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, `Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, `Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, `Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, `Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, `Event`.`category` AS `Event_category`, `Event`.`city` AS `Event_city`, `Event`.`country` AS `Event_country`, `Event`.`createdAt` AS `Event_createdAt`, `Event`.`description` AS `Event_description`, `Event`.`finishDate` AS `Event_finishDate`, `Event`.`imageUrl` AS `Event_imageUrl`, `Event`.`latitude` AS `Event_latitude`, `Event`.`longitude` AS `Event_longitude`, `Event`.`name` AS `Event_name`, `Event`.`startDate` AS `Event_startDate`, `Event`.`updatedAt` AS `Event_updatedAt`, `PaymentMethod`.`id` AS `PaymentMethod_id`, `PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, `PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, `PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, `PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, `PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, `PaymentMethod`.`type` AS `PaymentMethod_type`, `PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, `PaymentMethod`.`userID` AS `PaymentMethod_userID`, `PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` WHERE `Wristband`.`wristbandUserID` = ?;, recoverySuggestion=There is a possibility that there is a bug if this error persists. Please take a look at 
E/amplify:flutter:datastore(10685): https://github.com/aws-amplify/amplify-android/issues to see if there are any existing issues that 
E/amplify:flutter:datastore(10685): match your scenario, and file an issue with the details of the bug if there isn't.}
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLCommandProcessor.dataStoreException(SQLCommandProcessor.java:86)
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLCommandProcessor.rawQuery(SQLCommandProcessor.java:54)
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$query$5$com-amplifyframework-datastore-storage-sqlite-SQLiteStorageAdapter(SQLiteStorageAdapter.java:426)
E/amplify:flutter:datastore(10685):     ... 6 more
E/amplify:flutter:datastore(10685): Caused by: android.database.sqlite.SQLiteException: no such column: User2.authUser2ID (code 1 SQLITE_ERROR): , while compiling: SELECT `User`.`id` AS `User_id`, `User`.`authUserID` AS `User_authUserID`, `User`.`createdAt` AS `User_createdAt`, `User`.`email` AS `User_email`, `User`.`emailConfirmed` AS `User_emailConfirmed`, `User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, `User`.`updatedAt` AS `User_updatedAt`, `User`.`userAccountInfoId` AS `User_userAccountInfoId`, `User`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId`, `User2`.`id` AS `User_id2`, `User2`.`authUser2ID` AS `User_authUserID2`, `User2`.`createdAt` AS `User_createdAt2`, `User2`.`email` AS `User_email2`, `User2`.`emailConfirmed` AS `User_emailConfirmed2`, `User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, `User2`.`updatedAt` AS `User_updatedAt2`, `User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, `User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, `Wristband`.`id` AS `Wristband_id`, `Wristband`.`createdAt` AS `Wristband_createdAt`, `Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, `Wristband`.`eventID` AS `Wristband_eventID`, `Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, `Wristband`.`pinCode` AS `Wristband_pinCode`, `Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, `Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, `Wristband`.`updatedAt` AS `Wristband_updatedAt`, `Wristband`.`uuid` AS `Wristband_uuid`, `Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, `Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, `Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, `Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, `Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, `Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, `Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, `Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, `Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, `Event`.`category` AS `Event_category`, `Event`.`city` AS `Event_city`, `Event`.`country` AS `Event_country`, `Event`.`createdAt` AS `Event_createdAt`, `Event`.`description` AS `Event_description`, `Event`.`finishDate` AS `Event_finishDate`, `Event`.`imageUrl` AS `Event_imageUrl`, `Event`.`latitude` AS `Event_latitude`, `Event`.`longitude` AS `Event_longitude`, `Event`.`name` AS `Event_name`, `Event`.`startDate` AS `Event_startDate`, `Event`.`updatedAt` AS `Event_updatedAt`, `PaymentMethod`.`id` AS `PaymentMethod_id`, `PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, `PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, `PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, `PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, `PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, `PaymentMethod`.`type` AS `PaymentMethod_type`, `PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, `PaymentMethod`.`userID` AS `PaymentMethod_userID`, `PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` WHERE `Wristband`.`wristbandUserID` = ?;
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1068)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:673)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:62)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1712)
E/amplify:flutter:datastore(10685):     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1651)
E/amplify:flutter:datastore(10685):     at com.amplifyframework.datastore.storage.sqlite.SQLCommandProcessor.rawQuery(SQLCommandProcessor.java:49)
E/amplify:flutter:datastore(10685):     ... 7 more

Categories

Steps to Reproduce

  1. Create an app
  2. Use DataStore inside
  3. Create complex graphql schema
  4. Run app a few times
  5. Switch between ens back and force

Screenshots

No response

Platforms

Android Device/Emulator API Level

API 31

Environment

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.50.1)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

• No issues found!

Dependencies

Dart SDK 2.17.6
Flutter SDK 3.0.5
wallet_app 1.0.17+18

dependencies:
- amplify_api 0.6.6 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.6 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_datastore 0.6.6 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.6.6 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- animated_text_kit 4.2.2 [flutter characters]
- build_runner 2.1.11 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- camera 0.10.0 [camera_android camera_avfoundation camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver]
- cloud_firestore 2.5.4 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- credit_card_scanner 1.0.4 [flutter]
- credit_card_type_detector 2.0.0
- cupertino_icons 1.0.5
- currency_text_input_formatter 2.1.7 [flutter intl]
- dio 4.0.6 [http_parser path]
- dots_indicator 2.1.0 [flutter]
- dotted_border 2.0.0+2 [flutter path_drawing]
- equatable 2.0.3 [collection meta]
- firebase_analytics 9.1.12 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 3.4.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.19.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_web 1.6.6 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics 2.8.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.0.1 [flutter bloc provider]
- flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_multi_formatter 2.5.8 [flutter collection base58check bech32]
- flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows]
- flutter_svg 1.1.1+1 [flutter meta path_drawing vector_math xml]
- font_awesome_flutter 10.1.0 [flutter]
- geocoding 2.0.4 [flutter geocoding_platform_interface]
- google_maps_flutter 2.1.10 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- intl 0.17.0 [clock path]
- json_annotation 4.6.0 [meta]
- pin_code_fields 7.4.0 [flutter]
- provider 6.0.3 [collection flutter nested]
- pull_to_refresh 2.0.0 [flutter]
- qr_flutter 4.0.0 [flutter qr]
- syncfusion_flutter_datepicker 20.2.38 [flutter intl syncfusion_flutter_core]
- url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 3.0.6 [crypto]

transitive dependencies:
- _fe_analyzer_shared 41.0.0 [meta]
- amplify_api_android 0.6.6 [flutter]
- amplify_api_ios 0.6.6 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.6 [flutter]
- amplify_auth_cognito_ios 0.6.6 [amplify_core flutter]
- amplify_core 0.6.6 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.6 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.6 [flutter]
- amplify_flutter_ios 0.6.6 [amplify_core flutter]
- analyzer 4.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 2.3.1
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- base58check 2.0.0 [crypto collection]
- bech32 0.2.1 [convert]
- bloc 8.0.3 [meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.3.0 [analyzer async convert crypto glob logging meta path]
- build_config 1.0.0 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.0.9 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.3.3 [built_collection collection fixnum meta]
- camera_android 0.10.0 [camera_platform_interface flutter flutter_plugin_android_lifecycle stream_transform]
- camera_avfoundation 0.9.8+2 [camera_platform_interface flutter stream_transform]
- camera_platform_interface 2.2.0 [cross_file flutter plugin_platform_interface stream_transform]
- camera_web 0.3.0 [camera_platform_interface flutter flutter_web_plugins stream_transform]
- characters 1.2.0
- charcode 1.3.1
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- clock 1.1.0
- cloud_firestore_platform_interface 5.7.1 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.6.19 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.1.0 [built_collection built_value collection matcher meta]
- collection 1.16.0
- convert 3.0.2 [typed_data]
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- dart_style 2.2.3 [analyzer args path pub_semver source_span]
- fake_async 1.3.0 [clock collection]
- file 6.1.2 [meta path]
- firebase_analytics_platform_interface 3.1.10 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.0+17 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.3.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 3.3.19 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.4.3 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_crashlytics_platform_interface 3.2.10 [collection firebase_core flutter meta plugin_platform_interface]
- fixnum 1.0.1
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface]
- flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js]
- flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- frontend_server_client 2.1.3 [async path]
- geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- glob 2.1.0 [async collection file path string_scanner]
- google_maps_flutter_platform_interface 2.2.1 [collection flutter plugin_platform_interface stream_transform]
- graphs 2.1.0 [collection]
- http 0.13.5 [async http_parser meta path]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- io 1.0.3 [meta path string_scanner]
- js 0.6.4
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- mime 1.0.2
- nested 1.0.0 [flutter]
- package_config 2.1.0 [path]
- path 1.8.1
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- petitparser 5.0.0 [meta]
- plugin_platform_interface 2.1.2 [meta]
- pool 1.5.1 [async stack_trace]
- pub_semver 2.1.1 [collection meta]
- pubspec_parse 1.2.0 [checked_yaml collection json_annotation pub_semver yaml]
- qr 2.1.0 [meta]
- quiver 3.1.0 [matcher]
- shelf 1.3.1 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 1.0.2 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- syncfusion_flutter_core 20.2.38 [vector_math flutter]
- term_glyph 1.2.0
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 1.0.0 [json_annotation]
- typed_data 1.3.1 [collection]
- url_launcher_android 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface]
- url_launcher_web 2.0.12 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- vector_math 2.1.2
- watcher 1.0.1 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- xml 6.1.0 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]

Device

OS

Mac

Deployment Method

Amplify CLI

CLI Version

9.2.1

Additional Context

No response

Amplify Config

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "wallet1": {
                    "endpointType": "GraphQL",
                    "endpoint": "...",
                    "region": "us-east-2",
                    "authorizationType": "API_KEY",
                    "apiKey": "..."
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "...",
                        "Region": "us-east-2",
                        "AuthMode": "API_KEY",
                        "ApiKey": "...",
                        "ClientDatabasePrefix": "wallet1_API_KEY"
                    },
                    "wallet1_AWS_IAM": {
                        "ApiUrl": "...",
                        "Region": "us-east-2",
                        "AuthMode": "AWS_IAM",
                        "ClientDatabasePrefix": "wallet1_AWS_IAM"
                    }
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-2:d613a4d8-f3ba-414d-87f2-be81059dd7e7",
                            "Region": "us-east-2"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-2_ZMXzAoaDy",
                        "AppClientId": "...",
                        "Region": "us-east-2"
                    }
                },
                "Auth": {
                    "Default": {
                        "OAuth": {
                            "WebDomain": "...",
                            "AppClientId": "...",
                            "SignInRedirectURI": "myapp://",
                            "SignOutRedirectURI": "myapp://",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        },
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "socialProviders": [
                            "FACEBOOK",
                            "GOOGLE"
                        ],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "signupAttributes": [],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": [
                                "REQUIRES_LOWERCASE",
                                "REQUIRES_NUMBERS",
                                "REQUIRES_SYMBOLS",
                                "REQUIRES_UPPERCASE"
                            ]
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                }
            }
        }
    }
}''';

GraphQL schema

type UserBalanceDetail @model @auth(rules: [{allow: public}]) {
  id: ID!
  amount: Int
  paymentMethodType: PaymentMethodType
  userID: ID! @index(name: "byUser")
  paymentMethodID: ID! @index(name: "byPaymentMethod")
}

type EventCategory @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String
  events: [Event] @manyToMany(relationName: "EventEventCategory")
}

type AutoTopUpConfig @model @auth(rules: [{allow: public}]) {
  id: ID!
  threshold: Int
  amount: Int
  user: User @belongsTo
  paymentMethodID: ID! @index(name: "byPaymentMethod")
}

type Order @model @auth(rules: [{allow: public}]) {
  id: ID!
  description: String
  time: AWSDateTime
  amount: Int
  eventID: ID! @index(name: "byEvent")
  event: Event @belongsTo
  transactions: [Transaction] @hasMany(indexName: "byOrder", fields: ["id"])
}

enum TransactionType {
  DEPOSIT
  REFUND
  PURCHASE
}

type Transaction @model @auth(rules: [{allow: public}]) {
  id: ID!
  date: String
  type: TransactionType
  time: AWSDateTime
  amount: Int
  paymentMethodID: ID! @index(name: "byPaymentMethod")
  paymentMethod: PaymentMethod @belongsTo
  orderID: ID! @index(name: "byOrder")
  order: Order @belongsTo
  wristbandID: ID! @index(name: "byWristband")
}

type Wristband @model @auth(rules: [{allow: public}]) {
  id: ID!
  emailToSendReceipt: String
  wristbandNumber: String
  wristbandOwnerName: String
  wristbandOwnerPhoneNumber: String
  wristbandOwnerEmail: String
  topUpAmount: Int
  spendingLimit: Int
  pinCode: String
  uuid: ID
  balanceDetails: [BalanceDetail] @hasMany(indexName: "byWristband", fields: ["id"])
  eventID: ID! @index(name: "byEvent")
  event: Event @belongsTo
  wristbandUserID: ID! @index(name: "byUser")
  user: User @belongsTo
  paymentMethodID: ID! @index(name: "byPaymentMethod")
  paymentMethod: PaymentMethod @belongsTo
  transactions: [Transaction] @hasMany(indexName: "byWristband", fields: ["id"])
}

enum CardType {
  VISA
  MASTERCARD
}

enum PaymentMethodType {
  BILLFOLD_BALANCE
  CARD
  CASH
  PROMO_CASH
}

type PaymentMethod @model @auth(rules: [{allow: public}]) {
  id: ID!
  type: PaymentMethodType
  cardNumber: String
  cardExpiryDate: String
  cardHolderName: String
  cardType: CardType
  wristbands: [Wristband] @hasMany(indexName: "byPaymentMethod", fields: ["id"])
  userID: ID! @index(name: "byUser")
  user: User @belongsTo
  balanceDetails: [BalanceDetail] @hasMany(indexName: "byPaymentMethod", fields: ["id"])
  transactions: [Transaction] @hasMany(indexName: "byPaymentMethod", fields: ["id"])
  UserBalanceDetails: [UserBalanceDetail] @hasMany(indexName: "byPaymentMethod", fields: ["id"])
  AutoTopUpConfigs: [AutoTopUpConfig] @hasMany(indexName: "byPaymentMethod", fields: ["id"])
}

type BalanceDetail @model @auth(rules: [{allow: public}]) {
  id: ID!
  amount: Int
  wristbandID: ID! @index(name: "byWristband")
  paymentMethodID: ID! @index(name: "byPaymentMethod")
  paymentMethod: PaymentMethod @belongsTo
  paymentMethodType: PaymentMethodType
}

type Event @model @auth(rules: [{allow: public}]) {
  id: ID!
  startDate: AWSDate
  finishDate: AWSDate
  name: String
  description: String
  imageUrl: String
  latitude: Float
  longitude: Float
  address: String
  city: String
  country: String
  category: String
  wristbands: [Wristband] @hasMany(indexName: "byEvent", fields: ["id"])
  orders: [Order] @hasMany(indexName: "byEvent", fields: ["id"])
  categories: [EventCategory] @manyToMany(relationName: "EventEventCategory")
  favorers: [User] @manyToMany(relationName: "EventUser")
}

type AccountInfo @model @auth(rules: [{allow: public}]) {
  id: ID!
  firstName: String
  lastName: String
  address: String
  phoneNumber: String
  avatarUrl: String
  dateOfBirth: AWSDate
  user: User @belongsTo
}

type User @model @auth(rules: [{allow: public}]) {
  id: ID!
  authUserID: String
  linkedPaymentMethodId: ID
  email: String
  emailConfirmed: Boolean
  accountInfo: AccountInfo @hasOne
  wristbands: [Wristband] @hasMany(indexName: "byUser", fields: ["id"])
  paymentMethods: [PaymentMethod] @hasMany(indexName: "byUser", fields: ["id"])
  autoTopUpConfig: AutoTopUpConfig @hasOne
  favoriteEvents: [Event] @manyToMany(relationName: "EventUser")
  userBalanceDetails: [UserBalanceDetail] @hasMany(indexName: "byUser", fields: ["id"])
}
HuiSF commented 2 years ago

Hi @airon-tark thanks for opening the issue.

From where do these fields come from?

The DataStore implementation follows only provided schema to generate SQL commands querying local SQLite database. It won't use random names to present table like what the exception message showed. Therefore, mostly likely, your dev App has wrong schema information.

airon-tark commented 2 years ago

@HuiSF

Thanks for the answer

"The DataStore implementation follows only provided schema to generate SQL commands querying local SQLite database...."

Seems this is not the full truth. It follows, but make some other changes in the field names. As you can see from my schema:

So the wristband has two joint tables of model User. So it called the first one User and another one User2

E/amplify:flutter:datastore(13115): Caused by: DataStoreException{message=Invalid SQL statement: 
SELECT `User`.`id` AS `User_id`, 
`User`.`authUserID` AS `User_authUserID`, 
`User`.`createdAt` AS `User_createdAt`, 
`User`.`email` AS `User_email`, 
`User`.`emailConfirmed` AS `User_emailConfirmed`, 
`User`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId`, 
`User`.`updatedAt` AS `User_updatedAt`, 
`User`.`userAccountInfoId` AS `User_userAccountInfoId`, 
`User`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId`, 
`User2`.`id` AS `User_id2`, 
`User2`.`authUser2ID` AS `User_authUserID2`, 
`User2`.`createdAt` AS `User_createdAt2`, 
`User2`.`email` AS `User_email2`, 
`User2`.`emailConfirmed` AS `User_emailConfirmed2`, 
`User2`.`linkedPaymentMethodId` AS `User_linkedPaymentMethodId2`, 
`User2`.`updatedAt` AS `User_updatedAt2`, 
`User2`.`userAccountInfoId` AS `User_userAccountInfoId2`, 
`User2`.`userAutoTopUpConfigId` AS `User_userAutoTopUpConfigId2`, 
`Wristband`.`id` AS `Wristband_id`, 
`Wristband`.`createdAt` AS `Wristband_createdAt`, 
`Wristband`.`emailToSendReceipt` AS `Wristband_emailToSendReceipt`, 
`Wristband`.`eventID` AS `Wristband_eventID`, 
`Wristband`.`paymentMethodID` AS `Wristband_paymentMethodID`, 
`Wristband`.`pinCode` AS `Wristband_pinCode`, 
`Wristband`.`spendingLimit` AS `Wristband_spendingLimit`, 
`Wristband`.`topUpAmount` AS `Wristband_topUpAmount`, 
`Wristband`.`updatedAt` AS `Wristband_updatedAt`, 
`Wristband`.`uuid` AS `Wristband_uuid`, 
`Wristband`.`wristbandNumber` AS `Wristband_wristbandNumber`, 
`Wristband`.`wristbandOwnerEmail` AS `Wristband_wristbandOwnerEmail`, 
`Wristband`.`wristbandOwnerName` AS `Wristband_wristbandOwnerName`, 
`Wristband`.`wristbandOwnerPhoneNumber` AS `Wristband_wristbandOwnerPhoneNumber`, 
`Wristband`.`wristbandUserID` AS `Wristband_wristbandUserID`, 
`Wristband`.`eventWristbandsId` AS `Wristband_eventWristbandsId`, 
`Wristband`.`paymentMethodWristbandsId` AS `Wristband_paymentMethodWristbandsId`, 
`Wristband`.`userWristbandsId` AS `Wristband_userWristbandsId`, 
`Event`.`id` AS `Event_id`, `Event`.`address` AS `Event_address`, 
`Event`.`category` AS `Event_category`, 
`Event`.`city` AS `Event_city`, 
`Event`.`country` AS `Event_country`, 
`Event`.`createdAt` AS `Event_createdAt`, 
`Event`.`description` AS `Event_description`, 
`Event`.`finishDate` AS `Event_finishDate`, 
`Event`.`imageUrl` AS `Event_imageUrl`, 
`Event`.`latitude` AS `Event_latitude`, 
`Event`.`longitude` AS `Event_longitude`, 
`Event`.`name` AS `Event_name`, 
`Event`.`startDate` AS `Event_startDate`, 
`Event`.`updatedAt` AS `Event_updatedAt`, 
`PaymentMethod`.`id` AS `PaymentMethod_id`, 
`PaymentMethod`.`cardExpiryDate` AS `PaymentMethod_cardExpiryDate`, 
`PaymentMethod`.`cardHolderName` AS `PaymentMethod_cardHolderName`, 
`PaymentMethod`.`cardNumber` AS `PaymentMethod_cardNumber`, 
`PaymentMethod`.`cardType` AS `PaymentMethod_cardType`, 
`PaymentMethod`.`createdAt` AS `PaymentMethod_createdAt`, 
`PaymentMethod`.`type` AS `PaymentMethod_type`, 
`PaymentMethod`.`updatedAt` AS `PaymentMethod_updatedAt`, 
`PaymentMethod`.`userID` AS `PaymentMethod_userID`, 
`PaymentMethod`.`userPaymentMethodsId` AS `PaymentMethod_userPaymentMethodsId` FROM `Wristband` 
LEFT JOIN `Event` ON `Wristband`.`eventWristbandsId`=`Event`.`id` 
LEFT JOIN `PaymentMethod` ON `Wristband`.`paymentMethodWristbandsId`=`PaymentMethod`.`id` 
LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`
LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` 
WHERE wristbandUserID = ?;, 

These lines are important

LEFT JOIN `User` ON `PaymentMethod`.`userPaymentMethodsId`=`User`.`id`
LEFT JOIN `User` AS `User2` ON `Wristband`.`userWristbandsId`=`User2`.`id` 

Our team found these lines in the amplify-android code (here)

String columnName = column.getQuotedColumnName().replace(column.getTableName(), tableAlias);

We can see it is replacing the name of the column name with the alias table name. But it making a mistake and replacing the word in the middle of the next column name as well.

it trying to do

User.UserColumn -> User2.UserColumn  

but doing instead

User.UserColumn -> User2.User2Column  

and after that SQL can't find the column named User2Column.

The problem is in this commit when fixing this issue

How to fix: replace only the first occurrence of table name, not all

HuiSF commented 2 years ago

Thanks for the details @airon-tark ! I'll get in touch with amplify-android maintainers to fix the underlying issue.

AnilMaktala commented 2 years ago

Hi @airon-tark 👋 , we are working on reproducing the issue, could you please run below command and send us the report amplify diagnose --send-report

RobsonT commented 1 year ago

Hi @AnilMaktala, I having the same problem, has any news about this problem?

HuiSF commented 1 year ago

Another instance of the issue has been reported by amplify-flutter consumers. (linked to this issue)

The issue is at this line in below generated SQL command, where empresaLicensaEmpresa2Id should still be empresaLicensaEmpresaId due to what this comment pointed out.

`Empresa2`.`empresaLicensaEmpresa2Id` AS `Empresa_empresaLicensaEmpresaId2`, 

This is consistently reproducible with the following model relationship pattern, when querying ModelA this issue surfaces.

ModelA {
  modelB: @belongsTo ModelB
  modelC: @belongsTo ModelC
}

ModelB {
  modelD: @belongsTo ModelD
}

ModelC {
  modelD: @belongsTo ModelD
}

ModelD {
}

The complete sample of generated SQL command that breaks.

SELECT 
  `Usuario`.`id` AS `Usuario_id`, 
  `Usuario`.`admin` AS `Usuario_admin`, 
  `Usuario`.`ativo` AS `Usuario_ativo`, 
  `Usuario`.`createdAt` AS `Usuario_createdAt`, 
  `Usuario`.`email` AS `Usuario_email`, 
  `Usuario`.`login` AS `Usuario_login`, 
  `Usuario`.`nome` AS `Usuario_nome`, 
  `Usuario`.`permissao_cliente` AS `Usuario_permissao_cliente`, 
  `Usuario`.`permissao_colheita` AS `Usuario_permissao_colheita`, 
  `Usuario`.`permissao_cultura` AS `Usuario_permissao_cultura`, 
  `Usuario`.`permissao_estoque` AS `Usuario_permissao_estoque`, 
  `Usuario`.`permissao_exclusao` AS `Usuario_permissao_exclusao`, 
  `Usuario`.`permissao_insumo` AS `Usuario_permissao_insumo`, 
  `Usuario`.`permissao_logo` AS `Usuario_permissao_logo`, 
  `Usuario`.`permissao_manejo` AS `Usuario_permissao_manejo`, 
  `Usuario`.`permissao_ocorrencia` AS `Usuario_permissao_ocorrencia`, 
  `Usuario`.`permissao_pedido` AS `Usuario_permissao_pedido`, 
  `Usuario`.`permissao_perda` AS `Usuario_permissao_perda`, 
  `Usuario`.`permissao_precificacao` AS `Usuario_permissao_precificacao`, 
  `Usuario`.`permissao_propriedade` AS `Usuario_permissao_propriedade`, 
  `Usuario`.`permissao_relatorio` AS `Usuario_permissao_relatorio`, 
  `Usuario`.`permissao_safra` AS `Usuario_permissao_safra`, 
  `Usuario`.`permissao_servico` AS `Usuario_permissao_servico`, 
  `Usuario`.`permissao_usuario` AS `Usuario_permissao_usuario`, 
  `Usuario`.`responsavel_atualizacao_id` AS `Usuario_responsavel_atualizacao_id`, 
  `Usuario`.`responsavel_cadastro_id` AS `Usuario_responsavel_cadastro_id`, 
  `Usuario`.`telefon` AS `Usuario_telefon`, 
  `Usuario`.`updatedAt` AS `Usuario_updatedAt`, 
  `Usuario`.`empresaID` AS `Usuario_empresaID`, 
  `Propriedade`.`id` AS `Propriedade_id`, 
  `Propriedade`.`cpf_cnpj` AS `Propriedade_cpf_cnpj`, 
  `Propriedade`.`createdAt` AS `Propriedade_createdAt`, 
  `Propriedade`.`nome` AS `Propriedade_nome`, 
  `Propriedade`.`propriedadeEnderecoPropriedadeId` AS `Propriedade_propriedadeEnderecoPropriedadeId`, 
  `Propriedade`.`responsavel_atualizacao_id` AS `Propriedade_responsavel_atualizacao_id`, 
  `Propriedade`.`responsavel_cadastro_id` AS `Propriedade_responsavel_cadastro_id`, 
  `Propriedade`.`updatedAt` AS `Propriedade_updatedAt`, 
  `Propriedade`.`empresaID` AS `Propriedade_empresaID`, 
  `Empresa`.`id` AS `Empresa_id`, 
  `Empresa`.`cpf_cnpj` AS `Empresa_cpf_cnpj`, 
  `Empresa`.`createdAt` AS `Empresa_createdAt`, 
  `Empresa`.`email` AS `Empresa_email`, 
  `Empresa`.`empresaLicensaEmpresaId` AS `Empresa_empresaLicensaEmpresaId`, 
  `Empresa`.`nome` AS `Empresa_nome`, 
  `Empresa`.`nome_fantasia` AS `Empresa_nome_fantasia`, 
  `Empresa`.`telefone` AS `Empresa_telefone`, 
  `Empresa`.`updatedAt` AS `Empresa_updatedAt`, 
  `Empresa2`.`id` AS `Empresa_id2`, 
  `Empresa2`.`cpf_cnpj` AS `Empresa_cpf_cnpj2`, 
  `Empresa2`.`createdAt` AS `Empresa_createdAt2`, 
  `Empresa2`.`email` AS `Empresa_email2`, 
  `Empresa2`.`empresaLicensaEmpresa2Id` AS `Empresa_empresaLicensaEmpresaId2`, 
  `Empresa2`.`nome` AS `Empresa_nome2`, 
  `Empresa2`.`nome_fantasia` AS `Empresa_nome_fantasia2`, 
  `Empresa2`.`telefone` AS `Empresa_telefone2`, 
  `Empresa2`.`updatedAt` AS `Empresa_updatedAt2`, 
  `PropriedadeUsuario`.`id` AS `PropriedadeUsuario_id`, 
  `PropriedadeUsuario`.`createdAt` AS `PropriedadeUsuario_createdAt`, 
  `PropriedadeUsuario`.`responsavel_atualizacao_id` AS `PropriedadeUsuario_responsavel_atualizacao_id`, 
  `PropriedadeUsuario`.`responsavel_cadastro_id` AS `PropriedadeUsuario_responsavel_cadastro_id`, 
  `PropriedadeUsuario`.`updatedAt` AS `PropriedadeUsuario_updatedAt`, 
  `PropriedadeUsuario`.`propriedadeID` AS `PropriedadeUsuario_propriedadeID`, 
  `PropriedadeUsuario`.`usuarioID` AS `PropriedadeUsuario_usuarioID` 
FROM 
  `PropriedadeUsuario` 
  LEFT JOIN `Propriedade` ON `PropriedadeUsuario`.`propriedadeID` = `Propriedade`.`id` 
  LEFT JOIN `Empresa` ON `Propriedade`.`empresaID` = `Empresa`.`id` 
  LEFT JOIN `Usuario` ON `PropriedadeUsuario`.`usuarioID` = `Usuario`.`id` 
  LEFT JOIN `Empresa` AS `Empresa2` ON `Usuario`.`empresaID` = `Empresa2`.`id` 
WHERE 
  `PropriedadeUsuario`.`usuarioID` = ?;
eeatonaws commented 1 year ago

A fix for the issue has been released in Amplify Android 1.38.1 and 2.3.0.

github-actions[bot] commented 1 year ago

⚠️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.