Part of structured approach for UpdateExpressions: 1) Expression gets parsed into a tokenlist (tokenized) 2) Tokenlist get transformed to expression tree (AST) -> This commit 3) The AST gets validated (full semantic correctness) 4) AST gets processed to perform the update This commit uses the tokenlist to build an expression tree. This tree is not yet used. Still it allows to raise additional Validation Exceptions which previously were missed silently therefore it allows tests to catch these type of ValidationException. For that reason DDB UpdateExpressions will be parsed already. It also makes sure we won't break existing tests. One of the existing tests had to be changed in order to still pass: - test_dynamodb_table_with_range_key.test_update_item_with_expression This test passed in a numeric literal which is not supported by DynamoDB and with the current tokenization it would get the same error as in AWS DynamoDB.
30 lines
957 B
Python
30 lines
957 B
Python
class ReservedKeywords(list):
|
|
"""
|
|
DynamoDB has an extensive list of keywords. Keywords are considered when validating the expression Tree.
|
|
Not earlier since an update expression like "SET path = VALUE 1" fails with:
|
|
'Invalid UpdateExpression: Syntax error; token: "1", near: "VALUE 1"'
|
|
"""
|
|
|
|
KEYWORDS = None
|
|
|
|
@classmethod
|
|
def get_reserved_keywords(cls):
|
|
if cls.KEYWORDS is None:
|
|
cls.KEYWORDS = cls._get_reserved_keywords()
|
|
return cls.KEYWORDS
|
|
|
|
@classmethod
|
|
def _get_reserved_keywords(cls):
|
|
"""
|
|
Get a list of reserved keywords of DynamoDB
|
|
"""
|
|
try:
|
|
import importlib.resources as pkg_resources
|
|
except ImportError:
|
|
import importlib_resources as pkg_resources
|
|
|
|
reserved_keywords = pkg_resources.read_text(
|
|
"moto.dynamodb2.parsing", "reserved_keywords.txt"
|
|
)
|
|
return reserved_keywords.split()
|