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

Datastore - Changing Schema Breaks Query #1083

Closed
fjnoyp opened this issue Mar 2, 2021 · 3 comments
Closed

Datastore - Changing Schema Breaks Query #1083

fjnoyp opened this issue Mar 2, 2021 · 3 comments
Assignees
Labels
bug Something isn't working closing soon This issue will be closed in 7 days unless further comments are made. datastore Issues related to the DataStore category pending-community-response Issue is pending response from the issue requestor

Comments

@fjnoyp
Copy link

fjnoyp commented Mar 2, 2021

Describe the bug

For Amplify iOS - Datastore, if a user saves a model instance, then modifies its modelSchema to add another field, then runs amplify codegen models, a crash happens:

Query API failed. Error = DataStoreError: The operation couldn't be completed. (SQLite.Result error 0.)
Recovery suggestion: The operation couldn't be completed. (SQLite.Result error 0.)

To Reproduce
Steps to reproduce the behavior:

  1. Create the following schema:

type Note @model {
id: ID!
content: String!
}

  1. Save the model and then query. Observe no error.

  2. Update the schema:

type Note @model {
id: ID!
content: String!
name: String
}

  1. Run query. Don't save. Observe the error:
Query API failed. Error = DataStoreError: The operation couldn't be completed. (SQLite.Result error 0.)
Recovery suggestion: The operation couldn't be completed. (SQLite.Result error 0.)

Expected behavior
No error after changing the modelschema and running query

Screenshots
Here is the local DB on the phone. As you can see it's updated to include the extra fields:
image

Also on the AWS Amplify console you can see the extra fields as well:
image

Device Information (please complete the following information):

  • Device: Simulator
  • iOS Version: 14.2
@palpatim palpatim added bug Something isn't working datastore Issues related to the DataStore category pending-triage Issue is pending triage labels Mar 3, 2021
@palpatim
Copy link
Member

palpatim commented Mar 3, 2021

@fjnoyp Thanks for reporting this.

Right now we don't have a mechanism for supporting local migrations, but I wouldn't expect a crash--the documented behavior is that we remove local items and re-sync from the cloud.

@palpatim palpatim added investigating This issue is being investigated and removed pending-triage Issue is pending triage labels Mar 5, 2021
@ruiguoamz
Copy link
Contributor

Hi, @fjnoyp

Are you talking about the usage with sync enabled or disabled?
For whichever use case, I don't see a crash. But I do see subscription fails to be established for one case which I explain below

No matter for sync enabled or not, as long as there is a schema change, the local database will be cleared as @palpatim mentioned: we don't support for local data migration and we don't have control over customer's change of schema.

In this case the difference is the sync part:

If sync is enabled, when you change your schema, you should do a amplify push and then amplify codegen models, in this case, no error will be returned and thus no crash with the schema you provided. The sync will still be kicked off and when you do a query, the following result should be returned:

Note(id: "uuid********whatever", content: "note7", name: nil)

but if you skip doing amplify push, it fails to set up subscription, and since local database is cleared, you will get an empty array.

Maybe please provide more detailed reproduction steps that we can help out. Thanks

@ruiguoamz ruiguoamz added the pending-community-response Issue is pending response from the issue requestor label Mar 5, 2021
@palpatim palpatim removed the investigating This issue is being investigated label Mar 8, 2021
@royjit royjit added the closing soon This issue will be closed in 7 days unless further comments are made. label Mar 15, 2021
@github-actions
Copy link
Contributor

This issue is being automatically closed due to inactivity. If you believe it was closed by mistake, provide an update and re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing soon This issue will be closed in 7 days unless further comments are made. datastore Issues related to the DataStore category pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

4 participants