Merge pull request #925 from JackDanger/idempotent-dynamodb2-deletes

Idempotent Dynamodb2 deletes
This commit is contained in:
Steve Pulec 2017-05-10 22:07:12 -04:00 committed by GitHub
commit 15b811901b
4 changed files with 15 additions and 12 deletions

View File

@ -677,7 +677,7 @@ class DynamoDBBackend(BaseBackend):
return item
def delete_item(self, table_name, keys):
table = self.tables.get(table_name)
table = self.get_table(table_name)
if not table:
return None
hash_key, range_key = self.get_keys_value(table, keys)

View File

@ -450,18 +450,19 @@ class DynamoHandler(BaseResponse):
name = self.body['TableName']
keys = self.body['Key']
return_values = self.body.get('ReturnValues', '')
item = dynamodb_backend2.delete_item(name, keys)
if item:
if return_values == 'ALL_OLD':
item_dict = item.to_json()
else:
item_dict = {'Attributes': {}}
item_dict['ConsumedCapacityUnits'] = 0.5
return dynamo_json_dump(item_dict)
else:
table = dynamodb_backend2.get_table(name)
if not table:
er = 'com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException'
return self.error(er)
item = dynamodb_backend2.delete_item(name, keys)
if item and return_values == 'ALL_OLD':
item_dict = item.to_json()
else:
item_dict = {'Attributes': {}}
item_dict['ConsumedCapacityUnits'] = 0.5
return dynamo_json_dump(item_dict)
def update_item(self):
name = self.body['TableName']
key = self.body['Key']

View File

@ -316,7 +316,8 @@ def test_delete_item():
response.should.equal(True)
table.count().should.equal(0)
item.delete().should.equal(False)
# Deletes are idempotent
item.delete().should.equal(True)
@requires_boto_gte("2.9")

View File

@ -200,7 +200,8 @@ def test_delete_item():
table.count().should.equal(0)
item.delete().should.equal(False)
# Deletes are idempotent and 'False' here would imply an error condition
item.delete().should.equal(True)
@requires_boto_gte("2.9")