Skip to content
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

Not able to save anything in cloud datastore #507

Closed
mechaadi opened this issue Apr 11, 2021 · 4 comments
Closed

Not able to save anything in cloud datastore #507

mechaadi opened this issue Apr 11, 2021 · 4 comments

Comments

@mechaadi
Copy link

Describe the bug
I am trying to save items using Datastore.save() method but it's not letting me do it. But it seems like the data is being saved in local storage (sqlite), I tried to log events using Amplify hub and it's only logging "outboxStatus" and "outboxMutationEnqueued" events whenever the save() method is called.

To Reproduce
Steps to reproduce the behavior:
Following the documentation (https://docs.amplify.aws/lib/datastore/relational/q/platform/flutter#updated-schema)

Expected behavior
It should save the items in the cloud data store.

Screenshots
This is the data model of project
image

And this is the screenshot of content page which states "2 posts failed to sync"
image

Platform
Amplify Flutter currently supports iOS and Android. This issue is reproducible in (check all that apply):
[√] Android
[x] iOS

[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Version 10.0.19042.868], locale en-US)
   • Flutter version 2.0.4 at C:\flutter\flutter
   • Framework revision b1395592de (10 days ago), 2021-04-01 14:25:01 -0700
   • Engine revision 2dce47073a
   • Dart version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) 
   • Android SDK at C:\Users\Asus\AppData\Local\Android\Sdk
   • Platform android-30, build-tools 30.0.3
   • ANDROID_HOME = C:\Users\Asus\AppData\Local\Android\Sdk
   • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java       
   • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
   • All Android licenses accepted.

[√] Chrome - develop for the web
   • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe      

[√] Android Studio (version 4.1.0)
   • Android Studio at C:\Program Files\Android\Android Studio
   • Flutter plugin can be installed from:
      https://plugins.jetbrains.com/plugin/9212-flutter
   • Dart plugin can be installed from:
      https://plugins.jetbrains.com/plugin/6351-dart
   • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.55.1)
   • VS Code at C:\Users\Asus\AppData\Local\Programs\Microsoft VS Code
   • Flutter extension version 3.21.0

[√] Connected device (3 available)
   • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
   • Chrome (web)                • chrome        • web-javascript • Google Chrome 89.0.4389.114
   • Edge (web)                  • edge          • web-javascript • Microsoft Edge 89.0.774.75

• No issues found!

Smartphone (please complete the following information):

  • Device: Android emulator (Pixel 3a)
  • OS: Android 11

Additional context
Graphql Schema

enum PostStatus {
  ACTIVE
  INACTIVE
}

type Post @model {
  id: ID!
  title: String!
  rating: Int!
  status: PostStatus!
  # New field with @connection
  comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

# New model
type Comment @model @key(name: "byPost", fields: ["postID", "content"]) {
  id: ID!
  postID: ID!
  post: Post! @connection(fields: ["postID"])
  content: String!
}

Code to save the items


 Post post = Post(
                    title: 'My Post with comments',
                    rating: 10,
                    comments: [],
                    status: PostStatus.ACTIVE);
Comment comment = Comment(
                    post: post, // Directly pass in the post instance
                    content: 'Loving Amplify DataStore!');

await Amplify.DataStore.save(post);
print('Post saved');
await Amplify.DataStore.save(comment);
print('Comment saved');
                

Console logs (only two events i.e., "outboxStatus" and "outboxMutationEnqueued" are logged by Amplify Hub)

I/amplify:aws-datastore( 7392): Orchestrator lock acquired.
I/amplify:aws-datastore( 7392): Orchestrator lock released.
I/amplify:flutter:datastore( 7392): Saved item: SerializedModel{id='466d5261-5da7-4a38-b186-ae61a62e6649', serializedData={rating=10, comments=[], id=466d5261-5da7-4a38-b186-ae61a62e6649, 
title=My Post with comments, status=ACTIVE}, modelSchema=ModelSchema{name='Post', pluralName='Posts', authRules=[], fields={comments=ModelField{name='comments', javaClassForValue='interface java.util.List', targetType='Comment', isRequired=false, isArray=true, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, rating=ModelField{name='rating', javaClassForValue='class java.lang.Integer', targetType='Integer', isRequired=true, isArray=false, isEnum=false, isModel=false}, status=ModelField{name='status', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, title=ModelField{name='title', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}}, associations={comments=ModelAssociation{name='HasMany', targetName='null', associatedName='post', associatedType='Comment'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}}
I/flutter ( 7392): Post saved
I/amplify:aws-datastore( 7392): Orchestrator lock acquired.
I/amplify:aws-datastore( 7392): Orchestrator lock released.
I/amplify:aws-datastore( 7392): Successfully enqueued PendingMutation{mutatedItem=SerializedModel{id='466d5261-5da7-4a38-b186-ae61a62e6649', serializedData={rating=10, comments=[], id=466d5261-5da7-4a38-b186-ae61a62e6649, title=My Post with comments, status=ACTIVE}, modelSchema=ModelSchema{name='Post', pluralName='Posts', authRules=[], fields={comments=ModelField{name='comments', javaClassForValue='interface java.util.List', targetType='Comment', isRequired=false, isArray=true, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, rating=ModelField{name='rating', javaClassForValue='class java.lang.Integer', targetType='Integer', isRequired=true, isArray=false, isEnum=false, isModel=false}, status=ModelField{name='status', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, title=ModelField{name='title', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}}, associations={comments=ModelAssociation{name='HasMany', targetName='null', associatedName='post', associatedType='Comment'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}}, modelSchema=ModelSchema{name='Post', pluralName='Posts', authRules=[], fields={comments=ModelField{name='comments', javaClassForValue='interface 
java.util.List', targetType='Comment', isRequired=false, isArray=true, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, rating=ModelField{name='rating', javaClassForValue='class java.lang.Integer', targetType='Integer', isRequired=true, isArray=false, isEnum=false, isModel=false}, status=ModelField{name='status', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, title=ModelField{name='title', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}}, associations={comments=ModelAssociation{name='HasMany', targetName='null', associatedName='post', associatedType='Comment'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}, mutationType=CREATE, mutationId=4f3d21db-9ab0-11eb-a14e-6bc961b7ad30, predicate=MatchAllQueryPredicate}
I/amplify:flutter:datastore( 7392): Saved item: SerializedModel{id='471ff3df-ee47-4ea7-b25d-e7b4d4d93b22', serializedData={id=471ff3df-ee47-4ea7-b25d-e7b4d4d93b22, post=SerializedModel{id='466d5261-5da7-4a38-b186-ae61a62e6649', serializedData={rating=10, comments=[], id=466d5261-5da7-4a38-b186-ae61a62e6649, title=My Post with comments, status=ACTIVE}, modelSchema=null}, content=Loving Amplify DataStore!}, modelSchema=ModelSchema{name='Comment', pluralName='Comments', authRules=[], fields={content=ModelField{name='content', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, post=ModelField{name='post', javaClassForValue='interface com.amplifyframework.core.model.Model', targetType='Post', isRequired=true, isArray=false, isEnum=false, isModel=true}}, associations={post=ModelAssociation{name='BelongsTo', targetName='postID', associatedName='null', associatedType='Post'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}}
I/flutter ( 7392): outboxMutationEnqueued HUB EVENT
I/flutter ( 7392): outboxStatus HUB EVENT
I/flutter ( 7392): Comment saved
I/m.example.code( 7392): Background young concurrent copying GC freed 22986(1034KB) AllocSpace objects, 0(0B) LOS objects, 46% free, 3814KB/7101KB, paused 999us total 127.503ms
W/m.example.code( 7392): Reducing the number of considered missed Gc histogram windows from 110 to 100
I/amplify:aws-datastore( 7392): Successfully enqueued PendingMutation{mutatedItem=SerializedModel{id='471ff3df-ee47-4ea7-b25d-e7b4d4d93b22', serializedData={id=471ff3df-ee47-4ea7-b25d-e7b4d4d93b22, post=SerializedModel{id='466d5261-5da7-4a38-b186-ae61a62e6649', serializedData={rating=10, comments=[], id=466d5261-5da7-4a38-b186-ae61a62e6649, title=My Post with comments, status=ACTIVE}, modelSchema=null}, content=Loving Amplify DataStore!}, modelSchema=ModelSchema{name='Comment', pluralName='Comments', authRules=[], fields={content=ModelField{name='content', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, post=ModelField{name='post', javaClassForValue='interface com.amplifyframework.core.model.Model', 
targetType='Post', isRequired=true, isArray=false, isEnum=false, isModel=true}}, associations={post=ModelAssociation{name='BelongsTo', targetName='postID', associatedName='null', associatedType='Post'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}}, modelSchema=ModelSchema{name='Comment', pluralName='Comments', authRules=[], fields={content=ModelField{name='content', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, id=ModelField{name='id', javaClassForValue='class java.lang.String', targetType='String', isRequired=true, isArray=false, isEnum=false, isModel=false}, post=ModelField{name='post', javaClassForValue='interface com.amplifyframework.core.model.Model', targetType='Post', isRequired=true, isArray=false, isEnum=false, isModel=true}}, associations={post=ModelAssociation{name='BelongsTo', targetName='postID', associatedName='null', associatedType='Post'}}, indexes={}, modelClass=class com.amplifyframework.datastore.appsync.SerializedModel}, mutationType=CREATE, mutationId=4f4fe68c-9ab0-11eb-a14e-0d98ed948761, predicate=MatchAllQueryPredicate}
I/flutter ( 7392): outboxStatus HUB EVENT
I/flutter ( 7392): outboxMutationEnqueued HUB EVENT
@mechaadi
Copy link
Author

Tried to create a post directly using graphql api and it worked but still not able to save items from the flutter app.

image
image

@mechaadi
Copy link
Author

Looks like it's resolved, just deleted the amplify project, cleared the flutter cache and it worked.

Closing the issue!

@b-cancel
Copy link

This is a bug report I just filed that includes a couple of bugs I found and the workarounds to each
after reading your bug report I think it could help others that might land on this page
#822

@joshuamoreno1
Copy link

I'm having the sames issue, how did you resolve it? My model doesn't have custom fields like in this issue: #822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants