aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 248 forks source link

Model Failed to Sync in Content Tab of Amplify Studio #1849

Closed 0xraks closed 2 years ago

0xraks commented 2 years ago

Description

Dynamo DB that is created by Amplify has the following fields:

Any way I can disable it from creating these?

I'm trying to add data from AWS IoT Core to the DynamoDB with an SQL rule:

SELECT *, (cast(timestamp() as String)) as _lastChangedAt, from 'topic/MQTT'

The problem with this is that the IoT Core SQL Rule to add data from MQTT to the DB does not allow to have an alias to start with an underscore. So the above rule throws an error.

If I add an entry in the DB without "_lastChangedAt" field, Amplify throws an error "Models failed to sync". However, the data sync is working if I add the data item directly from the Amplify Studio and the Android application directly.

Could you please let me know if there is any possible workaround?

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Android Device/Emulator API Level

No response

Environment

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.19044.1706], locale en-IN)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.6)
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.67.2)
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!

Dependencies

Dart SDK 2.17.1
Flutter SDK 3.0.1
dashboard 0.0.0+1

dependencies:
- amplify_analytics_pinpoint 0.5.1 [amplify_analytics_pinpoint_android amplify_analytics_pinpoint_ios amplify_analytics_plugin_interface amplify_core flutter plugin_platform_interface]
- amplify_auth_cognito 0.5.1 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_auth_plugin_interface amplify_core collection flutter plugin_platform_interface]
- amplify_datastore 0.5.1 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 0.5.1 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_flutter_a
ndroid amplify_flutter_ios amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- cupertino_icons 1.0.5
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_login 3.2.0 [flutter font_awesome_flutter provider another_transformer_page_view another_flushbar flutter_signin_button quiver url_launcher]
- package_info_plus 1.4.2 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]

transitive dependencies:
- amplify_analytics_pinpoint_android 0.5.1 [flutter]
- amplify_analytics_pinpoint_ios 0.5.1 [flutter]
- amplify_analytics_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_api_plugin_interface 0.5.1 [amplify_core collection flutter json_annotation meta]
- amplify_auth_cognito_android 0.5.1 [flutter]
- amplify_auth_cognito_ios 0.5.1 [amplify_core flutter]
- amplify_auth_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_core 0.5.1 [collection date_time_format flutter meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.5.1 [flutter meta collection amplify_core]
- amplify_flutter_android 0.5.1 [flutter]
- amplify_flutter_ios 0.5.1 [amplify_core flutter]
- amplify_storage_plugin_interface 0.5.1 [flutter meta amplify_core]
- another_flushbar 1.10.29 [flutter]
- another_transformer_page_view 1.1.0 [flutter]
- async 2.8.2 [collection meta]
- characters 1.2.0
- charcode 1.3.1
- collection 1.16.0
- crypto 3.0.2 [typed_data]
- date_time_format 2.0.1
- ffi 1.2.1
- flutter_signin_button 2.0.0 [flutter font_awesome_flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- font_awesome_flutter 9.2.0 [flutter]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- js 0.6.4
- json_annotation 4.5.0 [meta]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- nested 1.0.0 [flutter]
- package_info_plus_linux 1.0.5 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.5 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 1.0.5 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.1
- plugin_platform_interface 2.1.2 [meta]
- provider 6.0.3 [collection flutter nested]
- quiver 3.1.0 [matcher]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- typed_data 1.3.1 [collection]
- url_launcher 6.1.3 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- 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.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.11 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- win32 2.6.1 [ffi]

Device

Pixel 4XL

OS

Android 12.0

CLI Version

8.4.0

Additional Context

No response

sundersc commented 2 years ago

@0xraks - Are there any errors in cloudwatch related to the SQL rule? DynamoDB throws an error when you combine with other fields. Instead of using , can you try mentioning the fields explicitly?

For example, the below query would throw an error.

SELECT *, "__typename" FROM "Table"

image

HuiSF commented 2 years ago

Hi @0xraks Thanks for opening this issue.

Have you enabled conflict detection while configuring the API category for DataStore?

Meta fields such as _lastChangedAt is added when enabling conflict detection. __typename is generally a required field working with GraphQL specification. Which cannot be removed.

Have you tried to wrap _lastChangedAt with double quotes?

0xraks commented 2 years ago

Hi @0xraks Thanks for opening this issue.

Have you enabled conflict detection while configuring the API category for DataStore?

Meta fields such as _lastChangedAt is added when enabling conflict detection. __typename is generally a required field working with GraphQL specification. Which cannot be removed.

Have you tried to wrap _lastChangedAt with double quotes?

Hi @HuiSF , Yes, I've tried the double quotes, but it doesn't help. The IoT core SQL is not allowing me to set an alias with anything beginning with an "-".

So SELECT timestamp() as lastChangedAt is OK. But SELECT timestamp() as _lastChangedAt is not good and throws the error.

Is there any way I can rename "_lastChangedAt" to something like "last_Changed_At" from the Amplify side?

HuiSF commented 2 years ago

Is there any way I can rename "_lastChangedAt" to something like "last_Changed_At" from the Amplify side?

Unfortunately, I don't think the conflict detection fields are customizable at this moment.

0xraks commented 2 years ago

I used AWS lambdas instead of using IoT-Core rules to insert entries to the DB and now amplify syncs with no Issues. Thanks All!