amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

Changing model prevents syncing

Open stephenjen opened this issue 1 year ago • 9 comments

Description

I recently change the permission of one of my models because for some reason even with the { allow: private, operations: [read] } non-owners were unable to access all the records in the model. Below are the changes:

  #type Friend @model @auth(rules: [{ allow: owner, ownerField: "pOwner"  }{ allow: private, operations: [read] }]) {
  type Friend @model @auth(rules: [{ allow: *private*, ownerField: "pOwner"  }]) {
      id: ID!
      ...
      pOwner: String!
  }

I changed the model by removing the { allow: private, operations: [read] }.

After I made this change and pushed it to the cloud, none of the models would sync after I stopped and started Datastore. It is only when I deleted and reinstalled the app did the app sync'ed properly.

Categories

  • [ ] Analytics
  • [ ] API (REST)
  • [ ] API (GraphQL)
  • [ ] Auth
  • [ ] Authenticator
  • [X] DataStore
  • [ ] Notifications (Push)
  • [ ] Storage

Steps to Reproduce

  1. Change auth rule for a model
  2. Push change to cloud
  3. Stop and start DataStore, in my case it happens when I log the user out and log in again
  4. Models do not sync

Screenshots

No response

Platforms

  • [X] iOS
  • [ ] Android
  • [ ] Web
  • [ ] macOS
  • [ ] Windows
  • [ ] Linux

Flutter Version

3.16.0

Amplify Flutter Version

1.6.0

Deployment Method

Amplify CLI

Schema

No response

stephenjen avatar Jul 15 '24 04:07 stephenjen

Hi @stephenjen, sorry you ran into this issue.

We've made several improvements in recent versions of Amplify Flutter, I would recommend updating to a newer version to see if the problem persists.

When you say models do not sync, what is logged? Any errors?

Equartey avatar Jul 15 '24 16:07 Equartey

No, no errors. Which version would you recommend I update to?

stephenjen avatar Jul 15 '24 23:07 stephenjen

@stephenjen The latest 2.3.0

Equartey avatar Jul 17 '24 20:07 Equartey

I've held off on updating because there are several major changes to Datastore in 2.0 that would require changes to my code. Are you fairly certain updating to 2.3.0 would resolve this issue?

stephenjen avatar Jul 18 '24 02:07 stephenjen

Hi @stephenjen, there's no guarantee that 2.3.0 will solve the problem, but the changes from 1.6.0 to 2.3.0 are quite significant. Primarily, the underlying iOS implementation is now on Amplify Swift V2 and all API calls are routed back through the Amplify Flutter Dart implementation of the API category.

Additionally, the DataStore category specific code changes required to migrate to V2 should be minimal. Please reference our upgrade guide: https://docs.amplify.aws/gen1/flutter/start/project-setup/upgrade-guide/#datastore

Equartey avatar Jul 18 '24 19:07 Equartey

Thank you for helping me with this. I need to implement push notifications, and I want to be on the latest and greatest for that, so perhaps now is a good time for me to update everything else - amplify, auth, storage, datastore.

I'll update this thread with my findings relating to this issue after the upgrade.

stephenjen avatar Jul 18 '24 22:07 stephenjen

Possibly a duplicate of (or at least related to) https://github.com/aws-amplify/amplify-flutter/issues/5184. see: https://github.com/aws-amplify/amplify-flutter/issues/5184#issuecomment-2251262129

Jordan-Nelson avatar Jul 25 '24 19:07 Jordan-Nelson

Hi @Jordan-Nelson Now that I am able to upgrade to 2.0.0 and issue #5184 has been resolved, I have come back to see if this issue is indeed resolved with the upgrade.

In 2.0.0, after I update a model by adding a new field of completionHours: AWSJSON, a query to the model generates the following error:

DataStore Exception { "message": "The operation couldn't be completed. (SQLite. Result error O.)", "recoverySuggestion": "The operation couldn't be completed. (SQLite.Result error O.)", "underlyingException": "The operation couldn't be completed. (SQLite. Result error O.)" }

When I log out of my app, which clears then stops Datastore, and then log in again and wait for everything to sync, the error remains. Only after I delete and reinstall the app does the error goes away. Not sure if its related to this original issue.

stephenjen avatar Aug 30 '24 01:08 stephenjen

Thanks for the update @stephenjen. Can you confirm the exact version of Amplify Flutter you are using? Are you using the latest (2.4.1)?

Can you confirm this would be the reproduction steps?

  • Launch an app on iOS using the latest version of Amplify Flutter (2.4.1) that uses DataStore with any schema.
  • Save and sync some data to the cloud
  • Add a new field to a model - completionHours: AWSJSON
  • Query the model with the new field
  • Observe that there is an error returned

Jordan-Nelson avatar Aug 30 '24 14:08 Jordan-Nelson

I'm still on version I downgraded to, 2.0.0. I'll give 2.4.1 a go and will report back.

stephenjen avatar Sep 04 '24 23:09 stephenjen

thanks @stephenjen

NikaHsn avatar Sep 05 '24 19:09 NikaHsn

@NikaHsn

Changing from

type Friend @model @auth(rules: [{ allow: owner, ownerField: "pOwner" }{ allow: private, operations: [read] }])

to

type Friend @model @auth(rules: [{ allow: private, ownerField: "pOwner" }])

and back again no longer causes sync issues.

Thanks!

stephenjen avatar Sep 06 '24 09:09 stephenjen

thanks for the update and I'm gald that the issue is resolved. I'm going to close this issue, please create a new issue if you have any other questions.

NikaHsn avatar Sep 06 '24 17:09 NikaHsn

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Sep 06 '24 17:09 github-actions[bot]