Fix DynamoDb2 ExpressionAttributeNames can start with a number (#3206)

When using pynamodb's support for transactions it makes use of of
ExpressionAttributeNames that look like #0 #1 etc. According to

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

And when testing against dynamodb-local these work without issue,
however, when testing with moto they fail.
This commit is contained in:
Iain Bullard 2020-07-31 17:46:48 +01:00 committed by GitHub
parent 8162947ebb
commit 88a1134657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -109,7 +109,7 @@ class ExpressionTokenizer(object):
@classmethod @classmethod
def is_expression_attribute(cls, input_string): def is_expression_attribute(cls, input_string):
return re.compile("^[a-zA-Z][a-zA-Z0-9_]*$").match(input_string) is not None return re.compile("^[a-zA-Z0-9][a-zA-Z0-9_]*$").match(input_string) is not None
@classmethod @classmethod
def is_expression_attribute_name(cls, input_string): def is_expression_attribute_name(cls, input_string):

View File

@ -219,6 +219,18 @@ def test_expression_tokenizer_single_set_action_attribute_name_valid_key():
] ]
def test_expression_tokenizer_single_set_action_attribute_name_leading_number():
set_action = "SET attr=#0"
token_list = ExpressionTokenizer.make_list(set_action)
assert token_list == [
Token(Token.ATTRIBUTE, "SET"),
Token(Token.WHITESPACE, " "),
Token(Token.ATTRIBUTE, "attr"),
Token(Token.EQUAL_SIGN, "="),
Token(Token.ATTRIBUTE_NAME, "#0"),
]
def test_expression_tokenizer_just_a_pipe(): def test_expression_tokenizer_just_a_pipe():
set_action = "|" set_action = "|"
try: try: