#2212 add support for delete on update_with_attribute_updates (#2213)

* add support for delete on update_with_attribute_updates
This commit is contained in:
Ber Zoidberg 2019-05-22 02:47:02 -07:00 committed by Terry Cain
parent bbd7fefb37
commit 1088c421d2
2 changed files with 41 additions and 0 deletions

View File

@ -294,6 +294,19 @@ class Item(BaseModel):
# TODO: implement other data types
raise NotImplementedError(
'ADD not supported for %s' % ', '.join(update_action['Value'].keys()))
elif action == 'DELETE':
if set(update_action['Value'].keys()) == set(['SS']):
existing = self.attrs.get(attribute_name, DynamoType({"SS": {}}))
new_set = set(existing.value).difference(set(new_value))
self.attrs[attribute_name] = DynamoType({
"SS": list(new_set)
})
else:
raise NotImplementedError(
'ADD not supported for %s' % ', '.join(update_action['Value'].keys()))
else:
raise NotImplementedError(
'%s action not support for update_with_attribute_updates' % action)
class StreamRecord(BaseModel):

View File

@ -1344,6 +1344,34 @@ def test_update_item_add_value_string_set():
'subject': '123',
})
@mock_dynamodb2
def test_update_item_delete_value_string_set():
table = _create_table_with_range_key()
table.put_item(Item={
'forum_name': 'the-key',
'subject': '123',
'string_set': set(['str1', 'str2']),
})
item_key = {'forum_name': 'the-key', 'subject': '123'}
table.update_item(
Key=item_key,
AttributeUpdates={
'string_set': {
'Action': u'DELETE',
'Value': set(['str2']),
},
},
)
returned_item = dict((k, str(v) if isinstance(v, Decimal) else v)
for k, v in table.get_item(Key=item_key)['Item'].items())
dict(returned_item).should.equal({
'string_set': set(['str1']),
'forum_name': 'the-key',
'subject': '123',
})
@mock_dynamodb2
def test_update_item_add_value_does_not_exist_is_created():