Skip to content

Commit 3739f18

Browse files
error message for null geometry (stac-utils#259)
* error message for null geometry * Update stac_fastapi/pgstac/transactions.py Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com> * Update tests/clients/test_postgres.py --------- Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>
1 parent 231d5c6 commit 3739f18

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
- add `write_connection_pool` option in `stac_fastapi.pgstac.db.connect_to_db` function
4545
- add `write_postgres_settings` option in `stac_fastapi.pgstac.db.connect_to_db` function to set specific settings for the `writer` DB connection pool
46+
- add specific error message when trying to create `Item` with null geometry (not supported by PgSTAC)
4647

4748
### removed
4849

stac_fastapi/pgstac/transactions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def _validate_item(
5757

5858
self._validate_id(body_item_id, request.app.state.settings)
5959

60+
if item.get("geometry", None) is None:
61+
raise HTTPException(
62+
status_code=400,
63+
detail=f"Missing or null `geometry` for Item ({body_item_id}). Geometry is required in pgstac.",
64+
)
65+
6066
if body_collection_id is not None and collection_id != body_collection_id:
6167
raise HTTPException(
6268
status_code=400,

tests/clients/test_postgres.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ async def test_create_item_bad_body(
152152
assert resp.status_code == 400
153153

154154

155+
async def test_create_item_no_geometry(
156+
app_client, load_test_data: Callable, load_test_collection
157+
):
158+
"""Items with missing or null Geometry should return an error"""
159+
coll = load_test_collection
160+
161+
item = load_test_data("test_item.json")
162+
_ = item.pop("bbox")
163+
item["geometry"] = None
164+
resp = await app_client.post(f"/collections/{coll['id']}/items", json=item)
165+
assert resp.status_code == 400
166+
assert "Geometry is required in pgstac." in resp.json()["detail"]
167+
168+
155169
async def test_update_item(app_client, load_test_collection, load_test_item):
156170
coll = load_test_collection
157171
item = load_test_item

0 commit comments

Comments
 (0)