Deleting from an unknown table raises error

If the table exists then we deletes are idempotent
This commit is contained in:
Jack Danger Canty 2017-05-08 17:25:59 -10:00
parent 02edc6fa00
commit 8e3d46fb05
3 changed files with 8 additions and 2 deletions

View File

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

View File

@ -418,6 +418,11 @@ class DynamoHandler(BaseResponse):
name = self.body['TableName'] name = self.body['TableName']
keys = self.body['Key'] keys = self.body['Key']
return_values = self.body.get('ReturnValues', '') return_values = self.body.get('ReturnValues', '')
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) item = dynamodb_backend2.delete_item(name, keys)
if item and return_values == 'ALL_OLD': if item and return_values == 'ALL_OLD':
item_dict = item.to_json() item_dict = item.to_json()

View File

@ -199,7 +199,8 @@ def test_delete_item():
table.count().should.equal(0) 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") @requires_boto_gte("2.9")