Dynamodb - ensure getItem does not use expression and non-expression (#5412)

This commit is contained in:
Juan Martinez 2022-08-24 06:48:59 -04:00 committed by GitHub
parent 6232ccfa57
commit f6bc8d4a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -459,7 +459,14 @@ class DynamoHandler(BaseResponse):
"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")
attributes_to_get = self.body.get("AttributesToGet")
if projection_expression and attributes_to_get:
raise MockValidationException(
"Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}"
)
expression_attribute_names = self.body.get("ExpressionAttributeNames")
if expression_attribute_names == {}:
if projection_expression is None:

View File

@ -412,6 +412,7 @@ def test_put_item_with_streams():
@mock_dynamodb
def test_basic_projection_expression_using_get_item():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
client = boto3.client("dynamodb", region_name="us-east-1")
# Create the DynamoDB table.
table = dynamodb.create_table(
@ -453,6 +454,17 @@ def test_basic_projection_expression_using_get_item():
{"forum_name": "the-key", "subject": "123", "body": "some test message"}
)
# Running this against AWS DDB gives an exception so make sure it also fails.:
with pytest.raises(client.exceptions.ClientError):
# botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem
# operation: "Can not use both expression and non-expression parameters in the same request:
# Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}"
table.get_item(
Key={"forum_name": "the-key", "subject": "123"},
ProjectionExpression="body",
AttributesToGet=["body"],
)
@mock_dynamodb
def test_basic_projection_expressions_using_scan():