Skip to content

Commit

Permalink
Fix DynamoDb2 ExpressionAttributeNames can start with a number
Browse files Browse the repository at this point in the history
When using pynamodb's support for transactions it makes use of of
ExpressionAttributeNames that look like #0 getmoto#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.
  • Loading branch information
iainb committed Jul 31, 2020
1 parent a9ac099 commit b2b316a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moto/dynamodb2/parsing/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def is_possible_token_boundary(cls, character):

@classmethod
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
def is_expression_attribute_name(cls, input_string):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_dynamodb2/test_dynamodb_expression_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
set_action = "|"
try:
Expand Down

0 comments on commit b2b316a

Please sign in to comment.