-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Missing fields in update mutation after calling .copyOf() multiple times #9891
Comments
Hi @chrisbonifacio, is anyone from the Amplify team able to look into this issue for us? It's a blocker for us updating to the latest version of aws-amplify. Thanks. |
Hi @dmcd2 - Our team is currently looking into this! We will update you with our findings. |
@dmcd2 In the meantime while we look into this, would you be able to aggregate the changes into one call of |
In case this might be a use case we're missing, could you explain why you had to use |
@chrisbonifacio We're using copyOf() in the context of a UI dialog. As the user makes changes in UI we update the corresponding fields in the model with their update. At the point of saving we also update some metadata in the model to capture who and when the change was made, so there are at least two copyOf() calls before the save. |
@dmcd2 thanks for the information on your use case. It looks like this feature was not originally officially supported and happened to work due to the implementation at the time. We are researching the possible impacts of adding official support to all platforms. As a workaround, you could maintain a separate state of changes and call // given original { name: 'original', planet: 'original' }
const hero = await DataStore.query(Hero, 'id-123');
const changes = {};
// user makes changes to name and planet
changes.name = 'Obi-Wan Kenobi';
changes.planet = 'Tatooine';
// ===============================
// later user makes another change to name
changes.name = 'Ben Kenobi'
const heroCopy = Hero.copyOf(hero, draft => {
Object.assign(draft, changes);
});
await DataStore.save(heroCopy);
// will save final hero as { name: 'Ben Kenobi', planet: 'Tatooine' } |
@dpilch Are you going to support this behaviour? I saw there was a PR to address this. We've been using the older version of amplify for a while now so we could wait for an update rather than changing our application at this point. |
We are still discussing support. I'll update here when the decision is reached. |
@dmcd2, We have decided to support consecutive |
@dpilch That's great, thank you. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
DataStore
Amplify Categories
api
Environment information
Describe the bug
During an update from amplify-aws 3.3.14 to 4.3.21 we have noticed a change in behaviour in which fields are included in an update mutation. It appears that fields that we have updated in our model objects are not being included in the resulting mutation when DataStore.save() is called.
On further investigation we have narrowed this down to the fact that our model objects are copied multiple times before the DataStore.save(). Only the fields updated in the last Model.copyOf() are present in the mutation, any changes made before that are missing.
If I console.log the the contents of the model from the last .copyOf() I can see all the fields I expect to be present. The mutation sent to AppSync does not match this.
This is a definite change in behaviour from 3.3.14 where we had no issues in saving data. Another difference is that update mutations now only contain (or are supposed) the fields that have changed rather than providing the full data as was the case in older versions. That looks to be an optimisation which makes sense.
Expected behavior
What I would expect to happen is that all changes made through the use of Model.copyOf() are present in an update mutation. Model objects can be copied multiple times with different fields changed each time. When DataStore.save() is called all the changes are rolled up into a single update mutation.
Reproduction steps
Examine the update mutation in browser Network tab or print out outboxMutationEnqueued, only the fields set in step 3 are present.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: