DynamoDB: transact_write_items() should return failing item (#5482)
This commit is contained in:
parent
5739db4701
commit
e230750a7c
@ -207,14 +207,14 @@ class TransactionCanceledException(DynamodbException):
|
|||||||
|
|
||||||
def __init__(self, errors):
|
def __init__(self, errors):
|
||||||
msg = self.cancel_reason_msg.format(
|
msg = self.cancel_reason_msg.format(
|
||||||
", ".join([str(code) for code, _ in errors])
|
", ".join([str(code) for code, _, _ in errors])
|
||||||
)
|
)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
error_type=TransactionCanceledException.error_type, message=msg
|
error_type=TransactionCanceledException.error_type, message=msg
|
||||||
)
|
)
|
||||||
reasons = [
|
reasons = [
|
||||||
{"Code": code, "Message": message} if code else {"Code": "None"}
|
{"Code": code, "Message": message, **item} if code else {"Code": "None"}
|
||||||
for code, message in errors
|
for code, message, item in errors
|
||||||
]
|
]
|
||||||
self.description = json.dumps(
|
self.description = json.dumps(
|
||||||
{
|
{
|
||||||
|
@ -1654,7 +1654,7 @@ class DynamoDBBackend(BaseBackend):
|
|||||||
raise MultipleTransactionsException()
|
raise MultipleTransactionsException()
|
||||||
target_items.add(item)
|
target_items.add(item)
|
||||||
|
|
||||||
errors = []
|
errors = [] # [(Code, Message, Item), ..]
|
||||||
for item in transact_items:
|
for item in transact_items:
|
||||||
try:
|
try:
|
||||||
if "ConditionCheck" in item:
|
if "ConditionCheck" in item:
|
||||||
@ -1738,14 +1738,14 @@ class DynamoDBBackend(BaseBackend):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
errors.append((None, None))
|
errors.append((None, None, None))
|
||||||
except MultipleTransactionsException:
|
except MultipleTransactionsException:
|
||||||
# Rollback to the original state, and reraise the error
|
# Rollback to the original state, and reraise the error
|
||||||
self.tables = original_table_state
|
self.tables = original_table_state
|
||||||
raise MultipleTransactionsException()
|
raise MultipleTransactionsException()
|
||||||
except Exception as e: # noqa: E722 Do not use bare except
|
except Exception as e: # noqa: E722 Do not use bare except
|
||||||
errors.append((type(e).__name__, e.message))
|
errors.append((type(e).__name__, e.message, item))
|
||||||
if set(errors) != set([(None, None)]):
|
if any([code is not None for code, _, _ in errors]):
|
||||||
# Rollback to the original state, and reraise the errors
|
# Rollback to the original state, and reraise the errors
|
||||||
self.tables = original_table_state
|
self.tables = original_table_state
|
||||||
raise TransactionCanceledException(errors)
|
raise TransactionCanceledException(errors)
|
||||||
|
@ -3882,7 +3882,11 @@ def test_transact_write_items_put_conditional_expressions():
|
|||||||
reasons = ex.value.response["CancellationReasons"]
|
reasons = ex.value.response["CancellationReasons"]
|
||||||
reasons.should.have.length_of(5)
|
reasons.should.have.length_of(5)
|
||||||
reasons.should.contain(
|
reasons.should.contain(
|
||||||
{"Code": "ConditionalCheckFailed", "Message": "The conditional request failed"}
|
{
|
||||||
|
"Code": "ConditionalCheckFailed",
|
||||||
|
"Message": "The conditional request failed",
|
||||||
|
"Item": {"id": {"S": "foo2"}, "foo": {"S": "bar"}},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
reasons.should.contain({"Code": "None"})
|
reasons.should.contain({"Code": "None"})
|
||||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||||
|
Loading…
Reference in New Issue
Block a user