Merge pull request #2491 from bblommers/bugfix/250
DynamoDB - Add validation for Query Key Expression
This commit is contained in:
commit
484da34022
@ -457,6 +457,9 @@ class DynamoHandler(BaseResponse):
|
|||||||
range_comparison = None
|
range_comparison = None
|
||||||
range_values = []
|
range_values = []
|
||||||
|
|
||||||
|
if '=' not in hash_key_expression:
|
||||||
|
return self.error('com.amazonaws.dynamodb.v20111205#ValidationException',
|
||||||
|
'Query key condition not supported')
|
||||||
hash_key_value_alias = hash_key_expression.split("=")[1].strip()
|
hash_key_value_alias = hash_key_expression.split("=")[1].strip()
|
||||||
# Temporary fix until we get proper KeyConditionExpression function
|
# Temporary fix until we get proper KeyConditionExpression function
|
||||||
hash_key = value_alias_map.get(hash_key_value_alias, {'S': hash_key_value_alias})
|
hash_key = value_alias_map.get(hash_key_value_alias, {'S': hash_key_value_alias})
|
||||||
|
@ -2705,6 +2705,31 @@ def test_item_size_is_under_400KB():
|
|||||||
Item={'id': {'S': 'foo'}, 'itemlist': {'L': [{'M': {'item1': {'S': large_item}}}]}})
|
Item={'id': {'S': 'foo'}, 'itemlist': {'L': [{'M': {'item1': {'S': large_item}}}]}})
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
# https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-KeyConditionExpression
|
||||||
|
def test_hash_key_cannot_use_begins_with_operations():
|
||||||
|
dynamodb = boto3.resource('dynamodb')
|
||||||
|
table = dynamodb.create_table(
|
||||||
|
TableName='test-table',
|
||||||
|
KeySchema=[{'AttributeName': 'key', 'KeyType': 'HASH'}],
|
||||||
|
AttributeDefinitions=[{'AttributeName': 'key', 'AttributeType': 'S'}],
|
||||||
|
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1})
|
||||||
|
|
||||||
|
items = [{'key': 'prefix-$LATEST', 'value': '$LATEST'},
|
||||||
|
{'key': 'prefix-DEV', 'value': 'DEV'},
|
||||||
|
{'key': 'prefix-PROD', 'value': 'PROD'}]
|
||||||
|
|
||||||
|
with table.batch_writer() as batch:
|
||||||
|
for item in items:
|
||||||
|
batch.put_item(Item=item)
|
||||||
|
|
||||||
|
table = dynamodb.Table('test-table')
|
||||||
|
with assert_raises(ClientError) as ex:
|
||||||
|
table.query(KeyConditionExpression=Key('key').begins_with('prefix-'))
|
||||||
|
ex.exception.response['Error']['Code'].should.equal('ValidationException')
|
||||||
|
ex.exception.response['Error']['Message'].should.equal('Query key condition not supported')
|
||||||
|
|
||||||
|
|
||||||
def assert_failure_due_to_item_size(func, **kwargs):
|
def assert_failure_due_to_item_size(func, **kwargs):
|
||||||
with assert_raises(ClientError) as ex:
|
with assert_raises(ClientError) as ex:
|
||||||
func(**kwargs)
|
func(**kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user