You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm fetching a model via Amplify.API.query and updating one of the model attributes. Then I'm saving that model again, but it doesn't update the attribute.
Here is what happens Mutation is triggered by user clicking on a button. On each click Amplify.Datastore.save(theModel) is called.
First click does nothing
Second click updates the _version but not the attribute.
Third click updates the version and the attribute (as expected).
The model I am trying to do this on has secondary index, but I also have another model (which doesn't have secondary index) and it doesn't work either. I update both models in the same way, but no luck.
I am not comfortable sharing the schema. So here is a sample schema with the same structure and GSI setup
What I have tried to fix
I have conflict resolution enabled . I tried auto-merge, optimistic, and disabled the conflict resolution but same issue each time.
Steps To Reproduce
Steps to reproduce the behavior:
I am going to assume you have the models and backend setup, so I will only list the swift code execution needed.!!!!! NOTE !!!!!!
This only happens if I clear the datastore before clicking the button. I need to clear datastore when new user logs in.
Before getting started
1.Clear the amplify datastore (each time you restart the app).
Setup a button to trigger these steps each time its clicked:2. Query the model by Id using Amplify.API.Query
3. Update one of the model attributes
4. Save that model via Amplify.Datastore.save()
Here is the code for the steps above
_update via DataStore_
varmodel=Amplify.API.query(MyModel.self, byId:"the_id")
model.attribute_C = ENUM_VAL_B; // This is new value for enum. Amplify.DataStore.save(model)
I also tried using Amplify.API.mutate instead of datastore, but it did not work.
_update via API mutate_
varmodel=Amplify.API.query(MyModel.self, byId:"the_id")
model.attribute_C = ENUM_VAL_B; // This is new value for enum. Amplify.API.mutate(model)
Expected behavior
The attribute on the model fetched via Amplify.API.query should be updated on first try.
Amplify Framework Version
12.6.0
Amplify Categories
API, DataStore
Dependency manager
Cocoapods
Swift version
6.9.2
CLI version
12.6.0
Xcode version
Version 15.2 (15C500b)
Relevant log output
No response
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
iOS 17.0
Device
iPhone 15 Pro Simulator
Specific to simulators
No. It happens on real device as well.
Additional context
No response
The text was updated successfully, but these errors were encountered:
I wasn't able to find the fix for this issue, but the workaround to this is using a custom lambda conflict resolver. Add a custom lambda resolver via amplify cli and you can configure how you want to deal with conflicts. In my case, I just resolved the conflict without doing checks for versions or anything.
Describe the bug
I'm fetching a model via Amplify.API.query and updating one of the model attributes. Then I'm saving that model again, but it doesn't update the attribute.
Here is what happens
Mutation is triggered by user clicking on a button. On each click Amplify.Datastore.save(theModel) is called.
The model I am trying to do this on has secondary index, but I also have another model (which doesn't have secondary index) and it doesn't work either. I update both models in the same way, but no luck.
I am not comfortable sharing the schema. So here is a sample schema with the same structure and GSI setup
enum MyEnum {
Enum_Val_A
Enum_Val_B
Enum_Val_C
Enum_Val_D
}
type MyModel @model @auth(rules: [{allow: public}]) {
id: ID!
attribute_A: ID! @Index(name: "myGSI", sortKeyFields: ["attribute_C"], queryField: "myQueryField")
attribute_B: ID!
attribute_C: MyEnum
attribute_D: ID
}
What I have tried to fix
I have conflict resolution enabled . I tried auto-merge, optimistic, and disabled the conflict resolution but same issue each time.
Steps To Reproduce
Expected behavior
The attribute on the model fetched via Amplify.API.query should be updated on first try.
Amplify Framework Version
12.6.0
Amplify Categories
API, DataStore
Dependency manager
Cocoapods
Swift version
6.9.2
CLI version
12.6.0
Xcode version
Version 15.2 (15C500b)
Relevant log output
No response
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
iOS 17.0
Device
iPhone 15 Pro Simulator
Specific to simulators
No. It happens on real device as well.
Additional context
No response
The text was updated successfully, but these errors were encountered: