diff --git a/CHANGES.md b/CHANGES.md index b29958eaa..39d1f6e21 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ * Manually exclude non-truthy optional values from sqlalchemy serialization of Collections ([#508](https://github.com/stac-utils/stac-fastapi/pull/508)) * Support `intersects` in GET requests ([#521](https://github.com/stac-utils/stac-fastapi/pull/521)) * Deleting items that had repeated ids in other collections ([#520](https://github.com/stac-utils/stac-fastapi/pull/520)) +* 404 for missing collection on /items for sqlalchemy ([#528](https://github.com/stac-utils/stac-fastapi/pull/528)) ### Deprecated diff --git a/stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py b/stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py index 68995d209..62289d2a0 100644 --- a/stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py +++ b/stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py @@ -110,6 +110,8 @@ def item_collection( """Read an item collection from the database.""" base_url = str(kwargs["request"].base_url) with self.session.reader.context_session() as session: + # Look up the collection first to get a 404 if it doesn't exist + _ = self._lookup_id(collection_id, self.collection_table, session) query = ( session.query(self.item_table) .join(self.collection_table) diff --git a/stac_fastapi/sqlalchemy/tests/resources/test_item.py b/stac_fastapi/sqlalchemy/tests/resources/test_item.py index b44aa9afc..5ecf51952 100644 --- a/stac_fastapi/sqlalchemy/tests/resources/test_item.py +++ b/stac_fastapi/sqlalchemy/tests/resources/test_item.py @@ -688,7 +688,7 @@ def test_item_search_get_query_extension(app_client, load_test_data): def test_get_missing_item_collection(app_client): """Test reading a collection which does not exist""" resp = app_client.get("/collections/invalid-collection/items") - assert resp.status_code == 200 + assert resp.status_code == 404 def test_pagination_item_collection(app_client, load_test_data):