Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions stac_fastapi/pgstac/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions tests/clients/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading