Fix: Calling dynamodb:UpdateItem with non-existent table name should raise ResourceNotFoundException

This commit is contained in:
Brian Pandola 2022-02-23 18:07:23 -08:00 committed by Brian Pandola
parent e3fc799b95
commit 181031db5f
2 changed files with 22 additions and 1 deletions

View File

@ -947,7 +947,13 @@ class DynamoHandler(BaseResponse):
"Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters: {UpdateExpression}",
)
# We need to copy the item in order to avoid it being modified by the update_item operation
existing_item = copy.deepcopy(self.dynamodb_backend.get_item(name, key))
try:
existing_item = copy.deepcopy(self.dynamodb_backend.get_item(name, key))
except ValueError:
return self.error(
"com.amazonaws.dynamodb.v20111205#ResourceNotFoundException",
"Requested resource not found",
)
if existing_item:
existing_attributes = existing_item.to_json()["Attributes"]
else:

View File

@ -534,3 +534,18 @@ def test_transact_write_items__too_many_transactions():
err = exc.value.response["Error"]
err["Code"].should.equal("ValidationException")
err["Message"].should.match("Member must have length less than or equal to 25")
@mock_dynamodb2
def test_update_item_non_existent_table():
client = boto3.client("dynamodb", region_name="us-west-2")
with pytest.raises(client.exceptions.ResourceNotFoundException) as exc:
client.update_item(
TableName="non-existent",
Key={"forum_name": {"S": "LOLCat Forum"}},
UpdateExpression="set Body=:Body",
ExpressionAttributeValues={":Body": {"S": ""}},
)
err = exc.value.response["Error"]
assert err["Code"].should.equal("ResourceNotFoundException")
assert err["Message"].should.equal("Requested resource not found")