Merge pull request #499 from im-auld/partial-save-support-with-range-key
Partial save support with range key
This commit is contained in:
commit
9b0bce93dc
2 changed files with 43 additions and 5 deletions
|
|
@ -500,12 +500,20 @@ class DynamoDBBackend(BaseBackend):
|
|||
def update_item(self, table_name, key, update_expression, attribute_updates):
|
||||
table = self.get_table(table_name)
|
||||
|
||||
if table.hash_key_attr in key:
|
||||
# Sometimes the key is wrapped in a dict with the key name
|
||||
key = key[table.hash_key_attr]
|
||||
if all([table.hash_key_attr in key, table.range_key_attr in key]):
|
||||
# Covers cases where table has hash and range keys, ``key`` param will be a dict
|
||||
hash_value = DynamoType(key[table.hash_key_attr])
|
||||
range_value = DynamoType(key[table.range_key_attr])
|
||||
elif table.hash_key_attr in key:
|
||||
# Covers tables that have a range key where ``key`` param is a dict
|
||||
hash_value = DynamoType(key[table.hash_key_attr])
|
||||
range_value = None
|
||||
else:
|
||||
# Covers other cases
|
||||
hash_value = DynamoType(key)
|
||||
range_value = None
|
||||
|
||||
hash_value = DynamoType(key)
|
||||
item = table.get_item(hash_value)
|
||||
item = table.get_item(hash_value, range_value)
|
||||
if update_expression:
|
||||
item.update(update_expression)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue