Skip to content

Commit f013d6f

Browse files
committed
fix: return 404 for missing collection on /items
sqlalchemy
1 parent 1ded5a5 commit f013d6f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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)