#3506 - DynamoDB - Allow StringSets to be passed to update_item() (#3519)

This commit is contained in:
Bert Blommers 2020-12-07 01:31:53 -08:00 committed by GitHub
parent d44beb0c9d
commit e1fc3a9596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -128,10 +128,10 @@ class Item(BaseModel):
new_value = list(update_action["Value"].values())[0]
if action == "PUT":
# TODO deal with other types
if isinstance(new_value, list):
self.attrs[attribute_name] = DynamoType({"L": new_value})
elif isinstance(new_value, set):
if set(update_action["Value"].keys()) == set(["SS"]):
self.attrs[attribute_name] = DynamoType({"SS": new_value})
elif isinstance(new_value, list):
self.attrs[attribute_name] = DynamoType({"L": new_value})
elif isinstance(new_value, dict):
self.attrs[attribute_name] = DynamoType({"M": new_value})
elif set(update_action["Value"].keys()) == set(["N"]):

View File

@ -5683,3 +5683,24 @@ def test_transact_get_items_should_return_empty_map_for_non_existent_item():
items.should.have.length_of(2)
items[0].should.equal({"Item": item})
items[1].should.equal({})
@mock_dynamodb2
def test_dynamodb_update_item_fails_on_string_sets():
dynamodb = boto3.resource("dynamodb", region_name="eu-west-1")
client = boto3.client("dynamodb", region_name="eu-west-1")
table = dynamodb.create_table(
TableName="test",
KeySchema=[{"AttributeName": "record_id", "KeyType": "HASH"},],
AttributeDefinitions=[{"AttributeName": "record_id", "AttributeType": "S"},],
BillingMode="PAY_PER_REQUEST",
)
table.meta.client.get_waiter("table_exists").wait(TableName="test")
attribute = {"test_field": {"Value": {"SS": ["test1", "test2"],}, "Action": "PUT"}}
client.update_item(
TableName="test",
Key={"record_id": {"S": "testrecord"}},
AttributeUpdates=attribute,
)