From 05f16cfcf9510c11e05ae384d0dcdf7914347072 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Wed, 18 Apr 2018 22:23:11 -0400 Subject: [PATCH] Fixes to dynamodb empty keys. --- moto/dynamodb2/responses.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/moto/dynamodb2/responses.py b/moto/dynamodb2/responses.py index fce321c3d..3c7e7ffc2 100644 --- a/moto/dynamodb2/responses.py +++ b/moto/dynamodb2/responses.py @@ -8,6 +8,18 @@ from moto.core.utils import camelcase_to_underscores, amzn_request_id from .models import dynamodb_backends, dynamo_json_dump +def has_empty_keys_or_values(_dict): + if _dict == "": + return True + if not isinstance(_dict, dict): + return False + return any( + key == '' or value == '' or + has_empty_keys_or_values(value) + for key, value in _dict.items() + ) + + class DynamoHandler(BaseResponse): def get_endpoint_name(self, headers): @@ -161,7 +173,7 @@ class DynamoHandler(BaseResponse): name = self.body['TableName'] item = self.body['Item'] - if any(list(param.values())[0] == '' for param in item.values() if isinstance(param, dict)): + if has_empty_keys_or_values(item): er = 'com.amazonaws.dynamodb.v20111205#ValidationException' return (400, {'server': 'amazon.com'},