This commit is contained in:
parent
201b61455b
commit
e09d35701f
@ -434,6 +434,12 @@ class DynamoHandler(BaseResponse):
|
|||||||
name = self.body["TableName"]
|
name = self.body["TableName"]
|
||||||
self.dynamodb_backend.get_table(name)
|
self.dynamodb_backend.get_table(name)
|
||||||
key = self.body["Key"]
|
key = self.body["Key"]
|
||||||
|
empty_keys = [k for k, v in key.items() if not next(iter(v.values()))]
|
||||||
|
if empty_keys:
|
||||||
|
raise MockValidationException(
|
||||||
|
"One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an "
|
||||||
|
f"empty string value. Key: {empty_keys[0]}"
|
||||||
|
)
|
||||||
projection_expression = self.body.get("ProjectionExpression")
|
projection_expression = self.body.get("ProjectionExpression")
|
||||||
expression_attribute_names = self.body.get("ExpressionAttributeNames")
|
expression_attribute_names = self.body.get("ExpressionAttributeNames")
|
||||||
if expression_attribute_names == {}:
|
if expression_attribute_names == {}:
|
||||||
@ -698,7 +704,7 @@ class DynamoHandler(BaseResponse):
|
|||||||
expr_names=expression_attribute_names,
|
expr_names=expression_attribute_names,
|
||||||
expr_values=expression_attribute_values,
|
expr_values=expression_attribute_values,
|
||||||
filter_expression=filter_expression,
|
filter_expression=filter_expression,
|
||||||
**filter_kwargs
|
**filter_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
@ -296,3 +296,27 @@ def test_update_item_with_long_string_range_key_exception():
|
|||||||
ex.value.response["Error"]["Message"].should.equal(
|
ex.value.response["Error"]["Message"].should.equal(
|
||||||
"One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes"
|
"One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb
|
||||||
|
def test_item_add_empty_key_exception():
|
||||||
|
name = "TestTable"
|
||||||
|
conn = boto3.client("dynamodb", region_name="us-west-2")
|
||||||
|
conn.create_table(
|
||||||
|
TableName=name,
|
||||||
|
KeySchema=[{"AttributeName": "forum_name", "KeyType": "HASH"}],
|
||||||
|
AttributeDefinitions=[{"AttributeName": "forum_name", "AttributeType": "S"}],
|
||||||
|
BillingMode="PAY_PER_REQUEST",
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
conn.get_item(
|
||||||
|
TableName=name,
|
||||||
|
Key={"forum_name": {"S": ""}},
|
||||||
|
)
|
||||||
|
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
||||||
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||||
|
ex.value.response["Error"]["Message"].should.equal(
|
||||||
|
"One or more parameter values are not valid. The AttributeValue for a key attribute "
|
||||||
|
"cannot contain an empty string value. Key: forum_name"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user