* add support for delete on update_with_attribute_updates
This commit is contained in:
parent
bbd7fefb37
commit
1088c421d2
@ -294,6 +294,19 @@ class Item(BaseModel):
|
|||||||
# TODO: implement other data types
|
# TODO: implement other data types
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'ADD not supported for %s' % ', '.join(update_action['Value'].keys()))
|
'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):
|
class StreamRecord(BaseModel):
|
||||||
|
@ -1344,6 +1344,34 @@ def test_update_item_add_value_string_set():
|
|||||||
'subject': '123',
|
'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
|
@mock_dynamodb2
|
||||||
def test_update_item_add_value_does_not_exist_is_created():
|
def test_update_item_add_value_does_not_exist_is_created():
|
||||||
|
Loading…
Reference in New Issue
Block a user