Skip to content

Stubber with "dynamodb_client.transact_write_items" is unable to produce error response for tests #3178

@brysontyrrell

Description

@brysontyrrell

Describe the bug

dynamodb_client.transact_write_items now returns "CancellationReasons" in the error response.

Attempting to write a test around this is not possible with the Stubber.

Here is the error response for a conditional check failure using a transaction with boto3:

{
    "Error": {
        "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]",
        "Code": "TransactionCanceledException"
    },
    "ResponseMetadata": {...},
    "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]",
    "CancellationReasons": [
        {
            "Code": "ConditionalCheckFailed",
            "Message": "The conditional request failed"
        }
    ]
}

CancellationReasons is a top level key instead of residing inside of the Error (also, strangely, Message is duplicated here as well).

The Stubber only allows adding metadata to the error or response. Both examples of these Stubber generated outputs are shown below (captured during pytest runs).

stubber.add_client_error(
        "transact_write_items",
        service_error_code="TransactionCanceledException",
        service_message="Transaction cancelled, please refer cancellation reasons for specific reasons [None, ConditionalCheckFailed]",
        response_meta={"CancellationReasons": [{"Code": "ConditionalCheckFailed"}]},
       # service_error_meta={...},
        http_status_code=400,
        expected_params=expected_params,
    )
{
    "ResponseMetadata": {
        "HTTPStatusCode": 400,
        "CancellationReasons": [
            {
                "Code": "ConditionalCheckFailed"
            }
        ]
    },
    "Error": {
        "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]",
        "Code": "TransactionCanceledException"
    }
}
{
    "ResponseMetadata": {
        "HTTPStatusCode": 400
    },
    "Error": {
        "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]",
        "Code": "TransactionCanceledException",
        "CancellationReasons": [
            {
                "Code": "ConditionalCheckFailed"
            }
        ]
    }
}

Expected behavior

This is the only operation in boto3 I've come across that breaks with the Stubber.

It is not clear to me if the Stubber needs to be updated to accomondate how transact_write_items returns "CancellationReasons", or if the implementation of returning "CancellationReasons" has a bug and those keys are supposed to be inside the Error.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions