From 8f9033f38bad9a47cf802eeee03effb3d6bdbbbe Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Sun, 22 Jun 2025 09:58:44 +0200 Subject: [PATCH 1/3] error message for null geometry --- CHANGES.md | 1 + stac_fastapi/pgstac/transactions.py | 6 ++++++ tests/clients/test_postgres.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 426768a1..b838437b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -43,6 +43,7 @@ - add `write_connection_pool` option in `stac_fastapi.pgstac.db.connect_to_db` function - add `write_postgres_settings` option in `stac_fastapi.pgstac.db.connect_to_db` function to set specific settings for the `writer` DB connection pool +- add specific error message when trying to create `Item` with null geometry (not supported by PgSTAC) ### removed diff --git a/stac_fastapi/pgstac/transactions.py b/stac_fastapi/pgstac/transactions.py index 27d3ae03..fa437190 100644 --- a/stac_fastapi/pgstac/transactions.py +++ b/stac_fastapi/pgstac/transactions.py @@ -57,6 +57,12 @@ def _validate_item( self._validate_id(body_item_id, request.app.state.settings) + if item.get("geometry", None) is None: + raise HTTPException( + status_code=400, + detail=f"Missing `geometry` for Item ({body_item_id}). Geometry is required to be not null in pgstac.", + ) + if body_collection_id is not None and collection_id != body_collection_id: raise HTTPException( status_code=400, diff --git a/tests/clients/test_postgres.py b/tests/clients/test_postgres.py index 4e066945..b569effc 100644 --- a/tests/clients/test_postgres.py +++ b/tests/clients/test_postgres.py @@ -152,6 +152,20 @@ async def test_create_item_bad_body( assert resp.status_code == 400 +async def test_create_item_no_geometry( + app_client, load_test_data: Callable, load_test_collection +): + """Items with missing or null Geometry should return an error""" + coll = load_test_collection + + item = load_test_data("test_item.json") + _ = item.pop("bbox") + item["geometry"] = None + resp = await app_client.post(f"/collections/{coll['id']}/items", json=item) + assert resp.status_code == 400 + assert "Geometry is required to be not null in pgstac." in resp.json()["detail"] + + async def test_update_item(app_client, load_test_collection, load_test_item): coll = load_test_collection item = load_test_item From 009a3951441bf1063ce9462efbb35269860c5716 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Tue, 24 Jun 2025 22:38:59 +0200 Subject: [PATCH 2/3] Update stac_fastapi/pgstac/transactions.py Co-authored-by: Pete Gadomski --- stac_fastapi/pgstac/transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stac_fastapi/pgstac/transactions.py b/stac_fastapi/pgstac/transactions.py index fa437190..f4ed11c9 100644 --- a/stac_fastapi/pgstac/transactions.py +++ b/stac_fastapi/pgstac/transactions.py @@ -60,7 +60,7 @@ def _validate_item( if item.get("geometry", None) is None: raise HTTPException( status_code=400, - detail=f"Missing `geometry` for Item ({body_item_id}). Geometry is required to be not null in pgstac.", + detail=f"Missing or null `geometry` for Item ({body_item_id}). Geometry is required in pgstac.", ) if body_collection_id is not None and collection_id != body_collection_id: From 2827b80fd78cdc3787b3831de3b69066c4f7b5a7 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Thu, 26 Jun 2025 22:11:55 +0200 Subject: [PATCH 3/3] Update tests/clients/test_postgres.py --- tests/clients/test_postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clients/test_postgres.py b/tests/clients/test_postgres.py index b569effc..cf1bf141 100644 --- a/tests/clients/test_postgres.py +++ b/tests/clients/test_postgres.py @@ -163,7 +163,7 @@ async def test_create_item_no_geometry( item["geometry"] = None resp = await app_client.post(f"/collections/{coll['id']}/items", json=item) assert resp.status_code == 400 - assert "Geometry is required to be not null in pgstac." in resp.json()["detail"] + assert "Geometry is required in pgstac." in resp.json()["detail"] async def test_update_item(app_client, load_test_collection, load_test_item):