Skip to content

Commit

Permalink
Queryables 404 for non-existent collection ids (#482)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mmcfarland authored Oct 25, 2022
1 parent fbdd993 commit 9ee7cb1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
### 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

### Removed

### 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
Expand Down
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 9ee7cb1

Please sign in to comment.