Skip to content

Commit

Permalink
Queryables 404's for non-existent collection
Browse files Browse the repository at this point in the history
Return a not-found response if pgstac does not return a queryable
object when passed a non-existing collection id.
  • Loading branch information
mmcfarland committed Oct 25, 2022
1 parent fbdd993 commit d9bcf6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/extensions/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
8 changes: 8 additions & 0 deletions stac_fastapi/pgstac/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d9bcf6a

Please sign in to comment.