From f3c1e21391aa27bb9df485c575a6da722adcb12b Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Mon, 11 Jan 2016 11:16:15 -0700 Subject: [PATCH] Delete missing attribute results in KeyError. --- moto/dynamodb2/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/moto/dynamodb2/models.py b/moto/dynamodb2/models.py index 94f726bc2..77b1434c3 100644 --- a/moto/dynamodb2/models.py +++ b/moto/dynamodb2/models.py @@ -125,7 +125,8 @@ class Item(object): for attribute_name, update_action in attribute_updates.items(): action = update_action['Action'] if action == 'DELETE' and not 'Value' in update_action: - del self.attrs[attribute_name] + if attribute_name in self.attrs: + del self.attrs[attribute_name] continue new_value = list(update_action['Value'].values())[0] if action == 'PUT': @@ -137,7 +138,8 @@ class Item(object): elif update_action['Value'].keys() == ['N']: self.attrs[attribute_name] = DynamoType({"N": new_value}) elif update_action['Value'].keys() == ['NULL']: - del self.attrs[attribute_name] + if attribute_name in self.attrs: + del self.attrs[attribute_name] else: self.attrs[attribute_name] = DynamoType({"S": new_value})