aws / aws/aws-appsync-community

[JS] DynamoDB UpdateItem return old values on ConditionalCheckFailedException

Open
#343 1 comment 2 reactions 0 assignees View on GitHub
pending triage
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

[Docs](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-condition-expressions) state that one should be able to see that data by default on `ctx.error.data`, but this doesn't seem to be the case.

```json
{
"arguments": {
"recordInput": {
"id": "1",
"sk": "1"
}
},
"prev": {
"result": {}
},
"stash": {},
"error": {
"message": "The conditional request failed (Service: DynamoDb, Status Code: 400, Request ID: 3S...)",
"type": "DynamoDB:ConditionalCheckFailedException"
},
"outErrors": []
}
```
There is also no `returnValuesOnConditionCheckFailure` attribute for the `UpdateItem` operation allowed.

Actual response (where docs state we should also be able to see the old/current record values):
```json
{
"data": {
"extendTtl": null
},
"errors": [
{
"path": [
"extendTtl"
],
"data": null,
"errorType": null,
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "The conditional request failed (Service: DynamoDb, Status Code: 400, Request ID: 3S...)"
}
]
}
```

With `TransactWriteItems`, where for some reason you can actually use `returnValuesOnConditionCheckFailure` for an `UpdateItem` operation, it seems to work as expected and the value is reachable in the ctx:
```json
{
"arguments": {
"recordInput": {
"id": "1",
"sk": "1"
}
},
"result": {
"cancellationReasons": [
{
"type": "ConditionalCheckFailed",
"message": "The conditional request failed",
"item": {
"test": {
"test1": true
},
"sk": "1",
"testField": "1-1",
"id": "1",
"ttl": 1705338604
}
}
]
},
"prev": {
"result": {}
},
"stash": {},
"error": {
"message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed] (Service: DynamoDb, Status Code: 400, Request ID: OTL...)",
"type": "DynamoDB:TransactionCanceledException"
},
"outErrors": []
}
```
But using `TransactWriteItems` isn't really an option, as it doesn't return all values of the updated record...

Contributor guide

Open the contributing guide

Research direction

Start with the linked AppSync JavaScript resolver DynamoDB condition-expression documentation and compare the documented UpdateItem behavior with the reported ctx.error.data output. Check the allowed UpdateItem attributes against TransactWriteItems, and consider the issue resolved only when the behavior is corrected or the documentation clearly reflects the supported response.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, javascript
Domain
api, database
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.