dynamodb2 support for default Action ('Put') in update_item (#3454)

Co-authored-by: Georgios Samaras <gsamaras@amazon.com>
This commit is contained in:
gsamaras 2020-11-14 11:10:38 +00:00 committed by GitHub
parent 9db62d32bf
commit d068653dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -109,7 +109,10 @@ class Item(BaseModel):
def update_with_attribute_updates(self, attribute_updates):
for attribute_name, update_action in attribute_updates.items():
action = update_action["Action"]
# Use default Action value, if no explicit Action is passed.
# Default value is 'Put', according to
# Boto3 DynamoDB.Client.update_item documentation.
action = update_action.get("Action", "PUT")
if action == "DELETE" and "Value" not in update_action:
if attribute_name in self.attrs:
del self.attrs[attribute_name]

View File

@ -2251,6 +2251,30 @@ def test_update_item_with_list():
resp["Item"].should.equal({"key": "the-key", "list": [1, 2]})
# https://github.com/spulec/moto/issues/2328
@mock_dynamodb2
def test_update_item_with_no_action_passed_with_list():
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
# Create the DynamoDB table.
dynamodb.create_table(
TableName="Table",
KeySchema=[{"AttributeName": "key", "KeyType": "HASH"}],
AttributeDefinitions=[{"AttributeName": "key", "AttributeType": "S"}],
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
)
table = dynamodb.Table("Table")
table.update_item(
Key={"key": "the-key"},
# Do not pass 'Action' key, in order to check that the
# parameter's default value will be used.
AttributeUpdates={"list": {"Value": [1, 2]}},
)
resp = table.get_item(Key={"key": "the-key"})
resp["Item"].should.equal({"key": "the-key", "list": [1, 2]})
# https://github.com/spulec/moto/issues/1342
@mock_dynamodb2
def test_update_item_on_map():