Skip to content

Commit

Permalink
Set collection_id on search for pgstac get_item; update to pgstac 0.3…
Browse files Browse the repository at this point in the history
….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
  • Loading branch information
lossyrob authored Sep 23, 2021
1 parent 710665d commit 27e1345
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"pytest-asyncio",
"pre-commit",
"requests",
"pypgstac==0.3.3",
"pypgstac==0.3.4",
"httpx",
"shapely",
],
Expand Down
6 changes: 4 additions & 2 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit 27e1345

Please sign in to comment.