Skip to content

Commit 27e1345

Browse files
authored
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 stac-utils/pgstac#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
1 parent 710665d commit 27e1345

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

CHANGES.md

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

2626
* Pin FastAPI to 0.67 to avoid issues with rendering OpenAPI documentation ([#246](https://github.com/stac-utils/stac-fastapi/pull/246))
2727
* Add `stac_version` to default search attributes ([#268](https://github.com/stac-utils/stac-fastapi/pull/268))
28+
* pgstac backend specifies collection_id when fetching a single item ([#279](https://github.com/stac-utils/stac-fastapi/pull/270))
2829

2930
## [2.1.0]
3031

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ services:
7171

7272
database:
7373
container_name: stac-db
74-
image: ghcr.io/stac-utils/pgstac:v0.3.3
74+
image: ghcr.io/stac-utils/pgstac:v0.3.4
7575
environment:
7676
- POSTGRES_USER=username
7777
- POSTGRES_PASSWORD=password

stac_fastapi/pgstac/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"pytest-asyncio",
2626
"pre-commit",
2727
"requests",
28-
"pypgstac==0.3.3",
28+
"pypgstac==0.3.4",
2929
"httpx",
3030
"shapely",
3131
],

stac_fastapi/pgstac/stac_fastapi/pgstac/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ async def get_item(self, item_id: str, collection_id: str, **kwargs) -> Item:
207207
# If collection does not exist, NotFoundError wil be raised
208208
await self.get_collection(collection_id, **kwargs)
209209

210-
req = PgstacSearch(ids=[item_id], limit=1)
210+
req = PgstacSearch(ids=[item_id], collections=[collection_id], limit=1)
211211
item_collection = await self._search_base(req, **kwargs)
212212
if not item_collection["features"]:
213-
raise NotFoundError(f"Collection {collection_id} does not exist.")
213+
raise NotFoundError(
214+
f"Item {item_id} in Collection {collection_id} does not exist."
215+
)
214216

215217
return Item(**item_collection["features"][0])
216218

0 commit comments

Comments
 (0)