Skip to content

Commit 7f60b8a

Browse files
authored
[sqlalchemy] Return 404 for missing collection on /items (#528)
* fix: return 404 for missing collection on /items sqlalchemy * chore: update changelog
1 parent 1ded5a5 commit 7f60b8a

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Manually exclude non-truthy optional values from sqlalchemy serialization of Collections ([#508](https://github.com/stac-utils/stac-fastapi/pull/508))
2727
* Support `intersects` in GET requests ([#521](https://github.com/stac-utils/stac-fastapi/pull/521))
2828
* Deleting items that had repeated ids in other collections ([#520](https://github.com/stac-utils/stac-fastapi/pull/520))
29+
* 404 for missing collection on /items for sqlalchemy ([#528](https://github.com/stac-utils/stac-fastapi/pull/528))
2930

3031
### Deprecated
3132

stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def item_collection(
110110
"""Read an item collection from the database."""
111111
base_url = str(kwargs["request"].base_url)
112112
with self.session.reader.context_session() as session:
113+
# Look up the collection first to get a 404 if it doesn't exist
114+
_ = self._lookup_id(collection_id, self.collection_table, session)
113115
query = (
114116
session.query(self.item_table)
115117
.join(self.collection_table)

stac_fastapi/sqlalchemy/tests/resources/test_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def test_item_search_get_query_extension(app_client, load_test_data):
688688
def test_get_missing_item_collection(app_client):
689689
"""Test reading a collection which does not exist"""
690690
resp = app_client.get("/collections/invalid-collection/items")
691-
assert resp.status_code == 200
691+
assert resp.status_code == 404
692692

693693

694694
def test_pagination_item_collection(app_client, load_test_data):

0 commit comments

Comments
 (0)