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..f4ed11c9 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 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: raise HTTPException( status_code=400, diff --git a/tests/clients/test_postgres.py b/tests/clients/test_postgres.py index 4e066945..cf1bf141 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 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