boto3 icon indicating copy to clipboard operation
boto3 copied to clipboard

`transact_write_items` doesn't return `CancellationReasons` when `ReturnValuesOnConditionCheckFailure` is set to 'ALL_OLD'

Open brysontyrrell opened this issue 5 years ago • 2 comments

Describe the bug

When calling transact_write_items with any TransactItems that specify ReturnValuesOnConditionCheckFailure, and any condition check of the transaction fails, there's no values returned in the ClientError exception that is raised.

Steps to reproduce

  • Create a write transaction to a DynamoDB table with a condition check that will fail. Set ReturnValuesOnConditionCheckFailure to ALL_OLD.
  • Specify to return ALL_OLD on condition check failures.
  • Run the transaction so the condition check fails.

Expected behavior

DynamoDB client raises TransactionCanceledException and the CancellationReasons are provided as a part of the error object.

Debug logs Full stack trace by adding boto3.set_stream_logger('') to your code.

(redacting some of this)

b'{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"None"},{"Code":"ConditionalCheckFailed","Item":{"sk":{"S":"**********"},"gsi1sk":{"S":"**********"},"pk":{"S":"**********"},"gsi1pk":{"S":"**********"},"type":{"S":"**********"}},"Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [None, ConditionalCheckFailed]"}'

Found #1990 which originally reported this.

The Java SDK seems to have implemented returning CancellationReasons.

Tagging @bradschm

brysontyrrell avatar Nov 09 '20 21:11 brysontyrrell

@brysontyrrell - Thank you for your post. According to the documentation

If using Java, DynamoDB lists the cancellation reasons on the CancellationReasons property. This property is not set for other languages.

This explains the behavior you are seeing. Marking this as feature request for supporting it with python.

swetashre avatar Nov 11 '20 00:11 swetashre

👋 it looks like this has been implemented? I have CacellationReasons in the error response now (was writing a sample for someone else and saw it there):

{
    "Error": {
        "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed, None]",
        "Code": "TransactionCanceledException"
    },
    "ResponseMetadata": {
        "RequestId": "XXXXX",
        "HTTPStatusCode": 400,
        "HTTPHeaders": {
            "server": "Server",
            "date": "Tue, 22 Feb 2022 20:19:37 GMT",
            "content-type": "application/x-amz-json-1.0",
            "content-length": "312",
            "connection": "keep-alive",
            "x-amzn-requestid": "XXXXX",
            "x-amz-crc32": "XXXXX"
        },
        "RetryAttempts": 0
    },
    "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed, None]",
    "CancellationReasons": [
        {
            "Code": "ConditionalCheckFailed",
            "Message": "The conditional request failed"
        },
        {
            "Code": "None"
        }
    ]
}

brysontyrrell avatar Feb 22 '22 20:02 brysontyrrell

Just checking in here as it looks like the CacellationReasons has been implemented to be in the error response. Thank you @brysontyrrell for following up, I was able to confirm it on my end as well. I'm going to close this issue now and please reach out to us again if you have any other questions!

aBurmeseDev avatar Nov 03 '22 18:11 aBurmeseDev