Skip to content

Commit 544ec39

Browse files
committed
fix: return 404 for missing collection on /items
sqlalchemy
1 parent edc97e9 commit 544ec39

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ 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+
collection = self._lookup_id(collection_id, self.collection_table, session)
115+
if collection is None:
116+
return NotFoundError(
117+
f"collection with id={collection_id} does not exist"
118+
)
113119
query = (
114120
session.query(self.item_table)
115121
.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)