Changing model prevents syncing
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
- Change auth rule for a model
- Push change to cloud
- Stop and start DataStore, in my case it happens when I log the user out and log in again
- 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
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?
No, no errors. Which version would you recommend I update to?
@stephenjen The latest 2.3.0
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?
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
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.
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
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.
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
I'm still on version I downgraded to, 2.0.0. I'll give 2.4.1 a go and will report back.
thanks @stephenjen
@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!
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.
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.