DynamoDB - raise exception for invalid parameter combination (#3755)
This commit is contained in:
parent
0317c502f0
commit
6a6a71ebff
@ -755,8 +755,12 @@ class DynamoHandler(BaseResponse):
|
||||
return_values = self.body.get("ReturnValues", "NONE")
|
||||
update_expression = self.body.get("UpdateExpression", "").strip()
|
||||
attribute_updates = self.body.get("AttributeUpdates")
|
||||
expression_attribute_names = self.body.get("ExpressionAttributeNames", {})
|
||||
expression_attribute_values = self.body.get("ExpressionAttributeValues", {})
|
||||
if update_expression and attribute_updates:
|
||||
er = "com.amazonaws.dynamodb.v20111205#ValidationException"
|
||||
return self.error(
|
||||
er,
|
||||
"Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters: {UpdateExpression}",
|
||||
)
|
||||
# We need to copy the item in order to avoid it being modified by the update_item operation
|
||||
existing_item = copy.deepcopy(self.dynamodb_backend.get_item(name, key))
|
||||
if existing_item:
|
||||
|
@ -5834,6 +5834,34 @@ def test_get_item_for_non_existent_table_raises_error():
|
||||
ex.value.response["Error"]["Message"].should.equal("Requested resource not found")
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_error_when_providing_expression_and_nonexpression_params():
|
||||
client = boto3.client("dynamodb", "eu-central-1")
|
||||
table_name = "testtable"
|
||||
client.create_table(
|
||||
TableName=table_name,
|
||||
KeySchema=[{"AttributeName": "pkey", "KeyType": "HASH"},],
|
||||
AttributeDefinitions=[{"AttributeName": "pkey", "AttributeType": "S"},],
|
||||
BillingMode="PAY_PER_REQUEST",
|
||||
)
|
||||
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.update_item(
|
||||
TableName=table_name,
|
||||
Key={"pkey": {"S": "testrecord"}},
|
||||
AttributeUpdates={
|
||||
"test_field": {"Value": {"SS": ["test1", "test2"],}, "Action": "PUT"}
|
||||
},
|
||||
UpdateExpression="DELETE orders :order",
|
||||
ExpressionAttributeValues={":order": {"SS": ["item"]}},
|
||||
)
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("ValidationException")
|
||||
err["Message"].should.equal(
|
||||
"Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters: {UpdateExpression}"
|
||||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_attribute_item_delete():
|
||||
name = "TestTable"
|
||||
|
Loading…
Reference in New Issue
Block a user