From 27e134589107654920c2f1dba54773c8c85d4e1a Mon Sep 17 00:00:00 2001 From: Rob Emanuele Date: Thu, 23 Sep 2021 11:35:09 -0400 Subject: [PATCH] Set collection_id on search for pgstac get_item; update to pgstac 0.3.4 (#270) * Update to pgstac 0.3.4 * Include collection_id in get_item search. I've seen strange behavior described in https://github.com/stac-utils/pgstac/issues/58, where searching only by an Item ID was returning the incorrect Item. Specifyng the Collection ID, which this method should be doing, solved this in my case. * Fix NotFoundError message * Update CHANGELOG --- CHANGES.md | 1 + docker-compose.yml | 2 +- stac_fastapi/pgstac/setup.py | 2 +- stac_fastapi/pgstac/stac_fastapi/pgstac/core.py | 6 ++++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bfd16d44d..cff6874b1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,7 @@ * Pin FastAPI to 0.67 to avoid issues with rendering OpenAPI documentation ([#246](https://github.com/stac-utils/stac-fastapi/pull/246)) * Add `stac_version` to default search attributes ([#268](https://github.com/stac-utils/stac-fastapi/pull/268)) +* pgstac backend specifies collection_id when fetching a single item ([#279](https://github.com/stac-utils/stac-fastapi/pull/270)) ## [2.1.0] diff --git a/docker-compose.yml b/docker-compose.yml index ec26770b4..4c84c7089 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,7 +71,7 @@ services: database: container_name: stac-db - image: ghcr.io/stac-utils/pgstac:v0.3.3 + image: ghcr.io/stac-utils/pgstac:v0.3.4 environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password diff --git a/stac_fastapi/pgstac/setup.py b/stac_fastapi/pgstac/setup.py index 62c6ab3cb..10d5c810e 100644 --- a/stac_fastapi/pgstac/setup.py +++ b/stac_fastapi/pgstac/setup.py @@ -25,7 +25,7 @@ "pytest-asyncio", "pre-commit", "requests", - "pypgstac==0.3.3", + "pypgstac==0.3.4", "httpx", "shapely", ], diff --git a/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py b/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py index 6ad16e77d..68719c035 100644 --- a/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py +++ b/stac_fastapi/pgstac/stac_fastapi/pgstac/core.py @@ -207,10 +207,12 @@ async def get_item(self, item_id: str, collection_id: str, **kwargs) -> Item: # If collection does not exist, NotFoundError wil be raised await self.get_collection(collection_id, **kwargs) - req = PgstacSearch(ids=[item_id], limit=1) + req = PgstacSearch(ids=[item_id], collections=[collection_id], limit=1) item_collection = await self._search_base(req, **kwargs) if not item_collection["features"]: - raise NotFoundError(f"Collection {collection_id} does not exist.") + raise NotFoundError( + f"Item {item_id} in Collection {collection_id} does not exist." + ) return Item(**item_collection["features"][0])