diff --git a/CHANGES.md b/CHANGES.md index 413b255c1..5a9100aa1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ ### Added * Add support in pgstac backend for /queryables and /collections/{collection_id}/queryables endpoints with functions exposed in pgstac 0.6.8 -* Update pgstac requirement to 0.6.8 +* Update pgstac requirement to 0.6.10 ### Changed @@ -13,6 +13,9 @@ ### Fixed +* Fix pgstac backend for /queryables endpoint to return 404 for non-existent collections [#482](https://github.com/stac-utils/stac-fastapi/pull/482) + + ## [2.4.2] ### Added diff --git a/docker-compose.yml b/docker-compose.yml index 8b262cc9e..613f98cf1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,7 +63,7 @@ services: database: container_name: stac-db - image: ghcr.io/stac-utils/pgstac:v0.6.8 + image: ghcr.io/stac-utils/pgstac:v0.6.10 environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password diff --git a/stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py b/stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py index 80c448c49..38ca8625e 100644 --- a/stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py +++ b/stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py @@ -6,6 +6,7 @@ from fastapi.responses import JSONResponse from stac_fastapi.types.core import AsyncBaseFiltersClient +from stac_fastapi.types.errors import NotFoundError class FiltersClient(AsyncBaseFiltersClient): @@ -32,6 +33,9 @@ async def get_queryables( collection=collection_id, ) queryables = await conn.fetchval(q, *p) + if not queryables: + raise NotFoundError(f"Collection {collection_id} not found") + queryables["$id"] = str(request.url) headers = {"Content-Type": "application/schema+json"} return JSONResponse(queryables, headers=headers) diff --git a/stac_fastapi/pgstac/tests/api/test_api.py b/stac_fastapi/pgstac/tests/api/test_api.py index 115cb5c63..01231aeba 100644 --- a/stac_fastapi/pgstac/tests/api/test_api.py +++ b/stac_fastapi/pgstac/tests/api/test_api.py @@ -415,3 +415,11 @@ async def test_collection_queryables(load_test_data, app_client, load_test_colle assert "properties" in q assert "id" in q["properties"] assert "eo:cloud_cover" in q["properties"] + + +@pytest.mark.asyncio +async def test_bad_collection_queryables( + load_test_data, app_client, load_test_collection +): + resp = await app_client.get("/collections/bad-collection/queryables") + assert resp.status_code == 404