DynamoDB - Error when providing table with 0 indexes (#4661)

This commit is contained in:
Bert Blommers 2021-12-05 22:05:30 -01:00 committed by GitHub
parent c4338b8aea
commit 4e8e91d11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -179,8 +179,20 @@ class DynamoHandler(BaseResponse):
# getting attribute definition
attr = body["AttributeDefinitions"]
# getting the indexes
global_indexes = body.get("GlobalSecondaryIndexes", [])
local_secondary_indexes = body.get("LocalSecondaryIndexes", [])
global_indexes = body.get("GlobalSecondaryIndexes")
if global_indexes == []:
return self.error(
"ValidationException",
"One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty",
)
global_indexes = global_indexes or []
local_secondary_indexes = body.get("LocalSecondaryIndexes")
if local_secondary_indexes == []:
return self.error(
"ValidationException",
"One or more parameter values were invalid: List of LocalSecondaryIndexes is empty",
)
local_secondary_indexes = local_secondary_indexes or []
# Verify AttributeDefinitions list all
expected_attrs = []
expected_attrs.extend([key["AttributeName"] for key in key_schema])

View File

@ -428,3 +428,41 @@ def test_hash_key_can_only_use_equals_operations(operator):
err = exc.value.response["Error"]
err["Code"].should.equal("ValidationException")
err["Message"].should.equal("Query key condition not supported")
@mock_dynamodb2
def test_creating_table_with_0_local_indexes():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
with pytest.raises(ClientError) as exc:
dynamodb.create_table(
TableName="test-table",
KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
LocalSecondaryIndexes=[],
)
err = exc.value.response["Error"]
err["Code"].should.equal("ValidationException")
err["Message"].should.equal(
"One or more parameter values were invalid: List of LocalSecondaryIndexes is empty"
)
@mock_dynamodb2
def test_creating_table_with_0_global_indexes():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
with pytest.raises(ClientError) as exc:
dynamodb.create_table(
TableName="test-table",
KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
GlobalSecondaryIndexes=[],
)
err = exc.value.response["Error"]
err["Code"].should.equal("ValidationException")
err["Message"].should.equal(
"One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty"
)