From a0ed89c92d673b5a962e68305a9f04c1a1d7a390 Mon Sep 17 00:00:00 2001 From: Ian Auld Date: Thu, 31 Dec 2015 10:27:01 -0800 Subject: [PATCH] Added support for partial_save on tables with a hash and range key; Issue #498 --- moto/dynamodb2/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/moto/dynamodb2/models.py b/moto/dynamodb2/models.py index 2b1a1b5ee..af67f5091 100644 --- a/moto/dynamodb2/models.py +++ b/moto/dynamodb2/models.py @@ -425,12 +425,17 @@ 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]): + hash_value = DynamoType(key[table.hash_key_attr]) + range_value = DynamoType(key[table.range_key_attr]) + elif table.hash_key_attr in key: + hash_value = DynamoType(key[table.hash_key_attr]) + range_value = None + else: + 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: