Skip to content

Commit 9ee7cb1

Browse files
authored
Queryables 404 for non-existent collection ids (#482)
* 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. * Changelog
1 parent fbdd993 commit 9ee7cb1

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CHANGES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
### Added
66

77
* Add support in pgstac backend for /queryables and /collections/{collection_id}/queryables endpoints with functions exposed in pgstac 0.6.8
8-
* Update pgstac requirement to 0.6.8
8+
* Update pgstac requirement to 0.6.10
99

1010
### Changed
1111

1212
### Removed
1313

1414
### Fixed
1515

16+
* Fix pgstac backend for /queryables endpoint to return 404 for non-existent collections [#482](https://github.com/stac-utils/stac-fastapi/pull/482)
17+
18+
1619
## [2.4.2]
1720

1821
### Added

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ services:
6363

6464
database:
6565
container_name: stac-db
66-
image: ghcr.io/stac-utils/pgstac:v0.6.8
66+
image: ghcr.io/stac-utils/pgstac:v0.6.10
6767
environment:
6868
- POSTGRES_USER=username
6969
- POSTGRES_PASSWORD=password

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)