DynamoDB: UpdateExpressions can contain a new-line (#7128)
This commit is contained in:
parent
9c58c689ad
commit
2228f07b80
@ -11,12 +11,12 @@ class Token:
|
|||||||
_TOKEN_INSTANCE = None
|
_TOKEN_INSTANCE = None
|
||||||
MINUS_SIGN = "-"
|
MINUS_SIGN = "-"
|
||||||
PLUS_SIGN = "+"
|
PLUS_SIGN = "+"
|
||||||
SPACE_SIGN = " "
|
|
||||||
EQUAL_SIGN = "="
|
EQUAL_SIGN = "="
|
||||||
OPEN_ROUND_BRACKET = "("
|
OPEN_ROUND_BRACKET = "("
|
||||||
CLOSE_ROUND_BRACKET = ")"
|
CLOSE_ROUND_BRACKET = ")"
|
||||||
COMMA = ","
|
COMMA = ","
|
||||||
SPACE = " "
|
SPACE = " "
|
||||||
|
NEW_LINE = "\n"
|
||||||
DOT = "."
|
DOT = "."
|
||||||
OPEN_SQUARE_BRACKET = "["
|
OPEN_SQUARE_BRACKET = "["
|
||||||
CLOSE_SQUARE_BRACKET = "]"
|
CLOSE_SQUARE_BRACKET = "]"
|
||||||
@ -24,12 +24,12 @@ class Token:
|
|||||||
SPECIAL_CHARACTERS = [
|
SPECIAL_CHARACTERS = [
|
||||||
MINUS_SIGN,
|
MINUS_SIGN,
|
||||||
PLUS_SIGN,
|
PLUS_SIGN,
|
||||||
SPACE_SIGN,
|
|
||||||
EQUAL_SIGN,
|
EQUAL_SIGN,
|
||||||
OPEN_ROUND_BRACKET,
|
OPEN_ROUND_BRACKET,
|
||||||
CLOSE_ROUND_BRACKET,
|
CLOSE_ROUND_BRACKET,
|
||||||
COMMA,
|
COMMA,
|
||||||
SPACE,
|
SPACE,
|
||||||
|
NEW_LINE,
|
||||||
DOT,
|
DOT,
|
||||||
OPEN_SQUARE_BRACKET,
|
OPEN_SQUARE_BRACKET,
|
||||||
CLOSE_SQUARE_BRACKET,
|
CLOSE_SQUARE_BRACKET,
|
||||||
@ -193,7 +193,7 @@ class ExpressionTokenizer(object):
|
|||||||
else:
|
else:
|
||||||
self.process_staged_characters()
|
self.process_staged_characters()
|
||||||
|
|
||||||
if character == Token.SPACE:
|
if character in [Token.SPACE, Token.NEW_LINE]:
|
||||||
if (
|
if (
|
||||||
len(self.token_list) > 0
|
len(self.token_list) > 0
|
||||||
and self.token_list[-1].type == Token.WHITESPACE
|
and self.token_list[-1].type == Token.WHITESPACE
|
||||||
|
@ -1,33 +1,42 @@
|
|||||||
import boto3
|
import boto3
|
||||||
|
import pytest
|
||||||
|
|
||||||
from moto import mock_dynamodb
|
from . import dynamodb_aws_verified
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb
|
@pytest.mark.aws_verified
|
||||||
def test_update_different_map_elements_in_single_request():
|
@dynamodb_aws_verified()
|
||||||
|
def test_update_different_map_elements_in_single_request(table_name=None):
|
||||||
# https://github.com/getmoto/moto/issues/5552
|
# https://github.com/getmoto/moto/issues/5552
|
||||||
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
||||||
dynamodb.create_table(
|
|
||||||
TableName="example_table",
|
|
||||||
KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}],
|
|
||||||
AttributeDefinitions=[
|
|
||||||
{"AttributeName": "id", "AttributeType": "S"},
|
|
||||||
],
|
|
||||||
BillingMode="PAY_PER_REQUEST",
|
|
||||||
)
|
|
||||||
record = {
|
record = {
|
||||||
"id": "example_id",
|
"pk": "example_id",
|
||||||
"d": {"hello": "h", "world": "w"},
|
"d": {"hello": "h", "world": "w"},
|
||||||
}
|
}
|
||||||
table = dynamodb.Table("example_table")
|
table = dynamodb.Table(table_name)
|
||||||
table.put_item(Item=record)
|
table.put_item(Item=record)
|
||||||
updated = table.update_item(
|
updated = table.update_item(
|
||||||
Key={"id": "example_id"},
|
Key={"pk": "example_id"},
|
||||||
UpdateExpression="set d.hello = :h, d.world = :w",
|
UpdateExpression="set d.hello = :h, d.world = :w",
|
||||||
ExpressionAttributeValues={":h": "H", ":w": "W"},
|
ExpressionAttributeValues={":h": "H", ":w": "W"},
|
||||||
ReturnValues="ALL_NEW",
|
ReturnValues="ALL_NEW",
|
||||||
)
|
)
|
||||||
assert updated["Attributes"] == {
|
assert updated["Attributes"] == {
|
||||||
"id": "example_id",
|
"pk": "example_id",
|
||||||
"d": {"hello": "H", "world": "W"},
|
"d": {"hello": "H", "world": "W"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use UpdateExpression that contains a new-line
|
||||||
|
# https://github.com/getmoto/moto/issues/7127
|
||||||
|
table.update_item(
|
||||||
|
Key={"pk": "example_id"},
|
||||||
|
UpdateExpression=(
|
||||||
|
"""
|
||||||
|
ADD
|
||||||
|
MyTotalCount :MyCount
|
||||||
|
"""
|
||||||
|
),
|
||||||
|
ExpressionAttributeValues={":MyCount": 5},
|
||||||
|
)
|
||||||
|
assert table.get_item(Key={"pk": "example_id"})["Item"]["MyTotalCount"] == 5
|
||||||
|
Loading…
Reference in New Issue
Block a user