DynamoDB: create_table() now validates the number of KeySchema-items (#7348)
This commit is contained in:
parent
e6818c3f1d
commit
aa043a0b2b
@ -237,6 +237,14 @@ class DynamoHandler(BaseResponse):
|
||||
raise UnknownKeyType(
|
||||
key_type=key_type, position=f"keySchema.{idx}.member.keyType"
|
||||
)
|
||||
if len(key_schema) > 2:
|
||||
key_elements = [
|
||||
f"KeySchemaElement(attributeName={key.get('AttributeName')}, keyType={key['KeyType']})"
|
||||
for key in key_schema
|
||||
]
|
||||
provided_keys = ", ".join(key_elements)
|
||||
err = f"1 validation error detected: Value '[{provided_keys}]' at 'keySchema' failed to satisfy constraint: Member must have length less than or equal to 2"
|
||||
raise MockValidationException(err)
|
||||
# getting attribute definition
|
||||
attr = body["AttributeDefinitions"]
|
||||
|
||||
|
@ -1242,3 +1242,34 @@ def test_scan_with_missing_value(table_name=None):
|
||||
err["Message"]
|
||||
== 'ExpressionAttributeValues contains invalid key: Syntax error; key: "loc"'
|
||||
)
|
||||
|
||||
|
||||
@mock_aws
|
||||
def test_too_many_key_schema_attributes():
|
||||
ddb = boto3.resource("dynamodb", "us-east-1")
|
||||
TableName = "my_test_"
|
||||
|
||||
AttributeDefinitions = [
|
||||
{"AttributeName": "UUID", "AttributeType": "S"},
|
||||
{"AttributeName": "ComicBook", "AttributeType": "S"},
|
||||
]
|
||||
|
||||
KeySchema = [
|
||||
{"AttributeName": "UUID", "KeyType": "HASH"},
|
||||
{"AttributeName": "ComicBook", "KeyType": "RANGE"},
|
||||
{"AttributeName": "Creator", "KeyType": "RANGE"},
|
||||
]
|
||||
|
||||
ProvisionedThroughput = {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}
|
||||
|
||||
expected_err = "1 validation error detected: Value '[KeySchemaElement(attributeName=UUID, keyType=HASH), KeySchemaElement(attributeName=ComicBook, keyType=RANGE), KeySchemaElement(attributeName=Creator, keyType=RANGE)]' at 'keySchema' failed to satisfy constraint: Member must have length less than or equal to 2"
|
||||
with pytest.raises(ClientError) as exc:
|
||||
ddb.create_table(
|
||||
TableName=TableName,
|
||||
KeySchema=KeySchema,
|
||||
AttributeDefinitions=AttributeDefinitions,
|
||||
ProvisionedThroughput=ProvisionedThroughput,
|
||||
)
|
||||
err = exc.value.response["Error"]
|
||||
assert err["Code"] == "ValidationException"
|
||||
assert err["Message"] == expected_err
|
||||
|
Loading…
Reference in New Issue
Block a user