aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

[JS] DynamoDB UpdateItem return old values on ConditionalCheckFailedException

Open Lorenzohidalgo opened this issue 2 years ago • 1 comments

Docs 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.

{
  "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):

{
  "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:

{
  "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...

Lorenzohidalgo avatar Jan 15 '24 18:01 Lorenzohidalgo

According to AWS support the docs are outdated and this field will not be present with APPSYNC_JS. I'm hoping for an official update here as well.

eriktim avatar Jun 17 '24 07:06 eriktim