amplify-cli: DataStore: Throws "UpdateItem on versioned data source requires the _version to be provided." when sending a mutation

Describe the bug

When trying to update an existing model via DataStore GraphQL throws the following error in the console and in the network tab:

“UpdateItem on versioned data source requires the _version to be provided.”

Yet the code is good and the _version field is provided. Seems that this was caused by my resolver (added via Amplify not manually) for the update mutation wasn’t DataStore aware (ie none of the required fields for DataStore where added to the resolver.

This was discussed last weekend in the Discord channel chat here https://discordapp.com/channels/705853757799399426/735987596462653461/789553458625249280

To Reproduce

Not sure how it got into this state. Sometimes I kill the amplify push (using Ctrl-C but only before it starts actually uploading stuff, if its got that far I leave it run) command if I’ve forgotten something. Or sometimes my connection times out (its pretty flakey at the minute) after 2 minutes and then I’m not sure what state it has left everything in, could it be caused by that?

At the point of this being “broken” running amplify status would say everything is up to date and as it should be yet my resolver was not setup as it should be. I’ve never edited a resolver manually until I found the issue and tried to fix it (which seems to have worked).

Steps to reproduce the behavior:

See attached two files, one called Sector which works (as it has all the DataStore stuff in it) and then the broken Staff model which doesn’t mention the DataStore fields (I’ve renamed them as .txt files as I can’t upload .vtl files).

staff-resolver.txt sector-resolver.txt

Winmerge screenshot showing some of the missing fields:

image

Now annoyingly I had fixed this last week but its just reoccurred today which is puzzling me. Team mate says they haven’t pushed. I’m going to re-do it and see if I made any mistakes and keep an eye on it.

Expected behavior A clear and concise description of what you expected to happen.

The resolver if DataStore is enabled so inject in all the right template code to wire up mutations via DataStore. Ideally it should be able to recover from an unknown state (cancelled push or timeout) if it doesn’t already.

What is Configured? If applicable, please provide what is configured for Amplify CLI:

amplify update api

  • Which resources do you have configured?
    • If applicable, please provide your aws-exports file:

const awsmobile = { “aws_project_region”: “eu-west-1”, “aws_appsync_graphqlEndpoint”: “https://xxxxx.eu-west-1.amazonaws.com/graphql”, “aws_appsync_region”: “eu-west-1”, “aws_appsync_authenticationType”: “AMAZON_COGNITO_USER_POOLS”, “aws_appsync_apiKey”: “xxxxxxxxxxxxxxxxxxxxx”, “aws_cloud_logic_custom”: [ { “name”: “webFormHandlerAPi”, “endpoint”: “https://xxxxxxxxxxxxx.eu-west-1.amazonaws.com/live”, “region”: “eu-west-1” }, { “name”: “customerCsvExport”, “endpoint”: “https://xxxxxxxxxxxxxx.eu-west-1.amazonaws.com/live”, “region”: “eu-west-1” } ], “aws_cognito_identity_pool_id”: “eu-west-1:xxxxxxxxxxx”, “aws_cognito_region”: “eu-west-1”, “aws_user_pools_id”: “eu-west-1xxxxxxxxxxxxxxxx”, “aws_user_pools_web_client_id”: “xxxxxxxxxxxxxxxxxxxxxx”, “oauth”: { “domain”: “xxxxxxxxxxxxxxxx.auth.eu-west-1.amazoncognito.com”, “scope”: [ “phone”, “email”, “openid”, “profile”, “aws.cognito.signin.user.admin” ], “redirectSignIn”: “http://localhost:3000/”, “redirectSignOut”: “http://localhost:3000/”, “responseType”: “code” }, “federationTarget”: “COGNITO_USER_POOLS”, “aws_user_files_s3_bucket”: “xxxxxxxxxx-live”, “aws_user_files_s3_bucket_region”: “eu-west-1” };


**Additional context**
Add any other context about the problem here.

**_You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app._**

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Transferring this to the CLI repo to get more eyes on it, as the issue doesn’t appear to be related to the JS library anymore.