Skip to content

Commit 933c26f

Browse files
committed
Queryables 404's for non-existent collection
Return a not-found response if pgstac does not return a queryable object when passed a non-existing collection id.
1 parent fbdd993 commit 933c26f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from fastapi.responses import JSONResponse
77

88
from stac_fastapi.types.core import AsyncBaseFiltersClient
9+
from stac_fastapi.types.errors import NotFoundError
910

1011

1112
class FiltersClient(AsyncBaseFiltersClient):
@@ -32,6 +33,9 @@ async def get_queryables(
3233
collection=collection_id,
3334
)
3435
queryables = await conn.fetchval(q, *p)
36+
if not queryables:
37+
raise NotFoundError(f"Collection {collection_id} not found")
38+
3539
queryables["$id"] = str(request.url)
3640
headers = {"Content-Type": "application/schema+json"}
3741
return JSONResponse(queryables, headers=headers)

stac_fastapi/pgstac/tests/api/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,11 @@ async def test_collection_queryables(load_test_data, app_client, load_test_colle
415415
assert "properties" in q
416416
assert "id" in q["properties"]
417417
assert "eo:cloud_cover" in q["properties"]
418+
419+
420+
@pytest.mark.asyncio
421+
async def test_bad_collection_queryables(
422+
load_test_data, app_client, load_test_collection
423+
):
424+
resp = await app_client.get("/collections/bad-collection/queryables")
425+
assert resp.status_code == 404

0 commit comments

Comments
 (0)