Merge pull request #2780 from heyderpd/master
fixing error when _get_default return value that already exists, on _get_appended_list
This commit is contained in:
commit
03164e7b60
@ -450,9 +450,9 @@ class Item(BaseModel):
|
|||||||
old_list_key = list_append_re.group(1)
|
old_list_key = list_append_re.group(1)
|
||||||
# old_key could be a function itself (if_not_exists)
|
# old_key could be a function itself (if_not_exists)
|
||||||
if old_list_key.startswith("if_not_exists"):
|
if old_list_key.startswith("if_not_exists"):
|
||||||
old_list = DynamoType(
|
old_list = self._get_default(old_list_key)
|
||||||
expression_attribute_values[self._get_default(old_list_key)]
|
if not isinstance(old_list, DynamoType):
|
||||||
)
|
old_list = DynamoType(expression_attribute_values[old_list])
|
||||||
else:
|
else:
|
||||||
old_list = self.attrs[old_list_key.split(".")[0]]
|
old_list = self.attrs[old_list_key.split(".")[0]]
|
||||||
if "." in old_list_key:
|
if "." in old_list_key:
|
||||||
|
@ -3634,6 +3634,31 @@ def test_update_supports_list_append_with_nested_if_not_exists_operation():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_update_supports_list_append_with_nested_if_not_exists_operation_and_property_already_exists():
|
||||||
|
dynamo = boto3.resource("dynamodb", region_name="us-west-1")
|
||||||
|
table_name = "test"
|
||||||
|
|
||||||
|
dynamo.create_table(
|
||||||
|
TableName=table_name,
|
||||||
|
AttributeDefinitions=[{"AttributeName": "Id", "AttributeType": "S"}],
|
||||||
|
KeySchema=[{"AttributeName": "Id", "KeyType": "HASH"}],
|
||||||
|
ProvisionedThroughput={"ReadCapacityUnits": 20, "WriteCapacityUnits": 20},
|
||||||
|
)
|
||||||
|
|
||||||
|
table = dynamo.Table(table_name)
|
||||||
|
|
||||||
|
table.put_item(Item={"Id": "item-id", "event_history": ["other_value"]})
|
||||||
|
table.update_item(
|
||||||
|
Key={"Id": "item-id"},
|
||||||
|
UpdateExpression="SET event_history = list_append(if_not_exists(event_history, :empty_list), :new_value)",
|
||||||
|
ExpressionAttributeValues={":empty_list": [], ":new_value": ["some_value"]},
|
||||||
|
)
|
||||||
|
table.get_item(Key={"Id": "item-id"})["Item"].should.equal(
|
||||||
|
{"Id": "item-id", "event_history": ["other_value", "some_value"]}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_update_catches_invalid_list_append_operation():
|
def test_update_catches_invalid_list_append_operation():
|
||||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user