-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Couple of Bugs that are preventing AppSync from Synchronizing Local Datastore Changes Globally/Online #822
Comments
Hi @b-cancel thanks for the details, much appreciated! For bug 0
For bug 1 Note: There is an issue #415 that may stop amplify-flutter doing in iOS platform. A fix PR #439 has been merged and pending release at this moment. For bug 2 For bug 3 For bug 4 |
Thanks for the quick reply @HuiSF below I refer to Amazon's Servers as whatever technology stores the data I can see from the AWS Admin Console for bug 0 what worked for me was adding (assuming you don't have a model named Repairer)
on the top of the 'amplify/backend/{api_name}/schema.graphql' file for bug 1 for bug 2 for bug 3* model examples (no fields are required except IDs of that object ofcourse) Insurance Car //the code below will save locally, but that new car won't show up on the AWS Admin Console for bug 4 I came up with this theory by...
|
Update on Bug 1 Needless to say this could be a lot of work depending on how your system is setup thankfully, like @HuiSF mentioned, a fix is comming soon since my app isn't in production I just create a hidden manual button to clear the DB and reload my home |
Bug 4 Extension |
Glad some tips helped. For bug 3 I believe the If the schema is defined like this, then all GraphQL types (e.g. mutation input type) will also require If you want to create For bug 4 From your updated comment above, it should be similar to what I talked about above, if the filed is marked as required, you will have to provide the data for that field, otherwise the underlying GraphQL request will fail. (saved to local but cannot sync to cloud) |
I can confirm that AWSJSON works as expected. It can be used in place of nested types but requires all clients to be updated since AppSync is expecting a JSON string instead of a GraphQL sub-type. The underlying data storage is identical so you can switch back to a nested type once the Flutter SDK supports them. |
Thanks for that confirmation @kjones And thanks for working through this with me @HuiSF Unfortunately, I mentioned both bugs 3 and 4, because all the mentioned fields were not required I just double checked the graph sql schema Another bit of evidence is that I was able to create what I wanted from the AWS Amplify Admin Console For example for bug 3: And for bug 4: But in both cases, creating them from the flutter app would not sync the changes to Amazon's servers Even when other models would sync edits, creates, and deletes Please let me know if I need to get more specific, and thanks again for your patience |
Thanks for the follow up @b-cancel sorry I misunderstood and thought Would you mind to post the model schema (You can find them in Could you also paste the logs when invoking |
@HuiSF Below I show three thing
--------------------------------------------------------------------------- Amplify.DataStore.save() doesn't usually log anything,
--------------------------------------------------------------------------- Below is everything I am using that saves properly *schema.graphql
*no logs coming from Amplify.DataStore.save()
--------------------------------------------------------------------------- Below is everything I am using that does not save properly *schema.graphql
*no logs coming from Amplify.DataStore.save()
and yet, here is evidence that I can read information without the number (in other words, that field isn't required) |
Alright @HuiSF I detailed everything above Additionally, to deal with bugs 1 & 2... Before making edits to a model
Tedious yes... but at least it works for now... |
Thanks @b-cancel I'll look into the issue around using In addition regarding this issue in bug 3
The It has a workaround you can try, by defining the type Car @model @key(name: "byInsuranceId", field: ["insuranceId"]) {
id: ID!
...
insuranceId: ID
insurance: Insurance @connection(fields: ["insuranceId"])
} This added |
For bug 4, when you are using type GraphQL request
GraphQL response
This is behavior of DynamoDB is expected... however, underlying APIs didn't throw this DynamoDB error, and the underlying APIs should remove local record for this type of failure. I will create issues for amplify-ios and amplify-android to track the issue. Currently, the workaround is to ensure the phone number to be synced is valid number. (DataStore plugins doesn't have client data validation at this moment) |
@HuiSF nice to know there are workarounds As for the AWSPhone issue... how is 1110004444 not a valid phone number? I tried using my own phone number "9567772692" or 956 777 2692 So I suspect this merits further investigation |
According to AppSync documentation about the scalar type
Other scalar types have certain validation rules as well. |
amplify-flutter DataStore currently lacks support of configuring custom error handler like other platform libraries. Which could be challenging for developers to catch unexpected errors happened during DataStore operations. This is something that probably need to be prioritized. |
FYI - Marking this as |
Regarding scalar type related issue discussed above, certain level of client validation is required. As each client may have different requirement and design, a generic client validation cannot be implemented within Amplify layer. Among the linked issues -
Therefore, I'm going to close this issue. Thanks again for the exemplary issue report, it helped amplify-flutter getting better! |
Thanks mate for this issues report, that saved me. If you use AWSJSON type , in Flutter it will locally works with simple String type (not casted as JSON object). |
In Summary*
There are a couple of issues that I've run into using the (Amplify Datastore and API Combination)
and I've been reading many of the bug reports, and many seem to be related,
so I thought I'd post a compilation here since I assume that posting each individually would be annoying
Hopefully, I can also point many folks here and show them the workarounds I used,
so they can at least get over these hurdles for now until the issues are repaired
The Net Effect
What led me to discover all these problems it that I was able to use datastore locally,
but these changes would not be visible from the AWS Amplify Admin console
Bug 0: the null safety flag on amplify/cli.json unsets itself automatically
nothing much else to say here
before I pull every change from the database I need to create the flag again
**Workaround: make sure to set the flag every time before pulling
Bug 1: if the schema online and locally are different, synchronization will fail without proper explanation
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: DataStoreException(message: The operation couldn’t be completed. (SQLite.Result error 0.), recoverySuggestion: The operation couldn’t be completed. (SQLite.Result error 0.), underlyingException: The operation couldn’t be completed. (SQLite.Result error 0.))
**Workaround: manually clear the datastore so that things are pulled cleanly from the global/online version
Bug 2: If you just change the type of a field the sync will fail silently
**Workaround... same as for Bug 1
Bug 3: creating an object that CAN but not SHOULD have a reference through another object through an ID will work locally but not globally
**Workaround... create an insurance that is empty... and check if the car has an insurance by simply checking a "hasInsurance" flag in the insurance object... then the car that I am saving will indeed have an insurance ID and the new car will be accepted globally
Bug 4: some types don't serialize properly
"Trusted Types" are the ones I've confirmed to work so far
*for anything that is a String in the dart models that are generated,
be careful when passing an empty string "" instead of null
(when I tried to create an object with a field of type AWSURL set to "" instead of null,
the data wouldn't push globally, the data would only stay on the local datastore)
--"Trusted Types"--
BASICS: [boolean, string, int]
AWS: [AWSEmail, AWSURL, AWSTimestamp]
CUSTOM: [any user creatable enum]
--I know there are issues with---
AWSPhone (So I use String)
--I've read that there have been issues with--
[float, AWSDate, AWSTime, AWSDateTime] (although I'm unsure if they are resolved)
--I haven't tested--
[AWSJSON, AWSIPAddress]
Platform
Amplify Flutter currently supports iOS and Android. This issue is reproducible in (check all that apply):
[X] Android
[X] iOS
The text was updated successfully, but these errors were encountered: