Fixed a bug where calling batch_get_item with non-existing tables names would not raise ResourceNotFoundException (#4344) (#4403)

This commit is contained in:
Maksymilian Babarowski 2021-10-13 12:36:16 +02:00 committed by GitHub
parent 9b5d42f7ef
commit e8cd02617d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -486,9 +486,15 @@ class DynamoHandler(BaseResponse):
results["Responses"][table_name] = []
for key in keys:
item = self.dynamodb_backend.get_item(
table_name, key, projection_expression
)
try:
item = self.dynamodb_backend.get_item(
table_name, key, projection_expression
)
except ValueError:
return self.error(
"com.amazonaws.dynamodb.v20111205#ResourceNotFoundException",
"Requested resource not found",
)
if item:
item_describe = item.describe_attrs(attributes_to_get)
results["Responses"][table_name].append(item_describe["Item"])

View File

@ -171,6 +171,18 @@ def test_update_item_range_key_set():
)
@mock_dynamodb2
def test_batch_get_item_non_existing_table():
client = boto3.client("dynamodb", region_name="us-west-2")
with pytest.raises(client.exceptions.ResourceNotFoundException) as exc:
client.batch_get_item(RequestItems={"my-table": {"Keys": [{"id": {"N": "0"}}]}})
err = exc.value.response["Error"]
assert err["Code"].should.equal("ResourceNotFoundException")
assert err["Message"].should.equal("Requested resource not found")
@mock_dynamodb2
def test_batch_write_item_non_existing_table():
client = boto3.client("dynamodb", region_name="us-west-2")