Skip to content

Queryables 404 for non-existent collection ids #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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