Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pagination to work with pgstac 0.9.X #140

Merged
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [Unreleased]

- Fix Docker compose file, so example data can be loaded into database (author @zstatmanweil, https://github.com/stac-utils/stac-fastapi-pgstac/pull/142)

- Handle `next` and `dev` tokens now returned as links from pgstac>=0.9.0 (author @zstatmanweil, https://github.com/stac-utils/stac-fastapi-pgstac/pull/140)
- Fix `filter` extension implementation in `CoreCrudClient`

## [3.0.0] - 2024-08-02
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"buildpg",
"brotli_asgi",
"pygeofilter>=0.2",
"pypgstac==0.8.*",
"pypgstac>=0.8,<0.10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stac-fastapi-pgstac should be compatible with 0.8 and 0.9

]

extra_reqs = {
"dev": [
"pystac[validation]",
"pypgstac[psycopg]==0.8.*",
"pypgstac[psycopg]==0.9.*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use pgstac 0.9.x in tests

"pytest-postgresql",
"pytest",
"pytest-cov",
Expand Down
13 changes: 11 additions & 2 deletions stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,17 @@ async def _search_base( # noqa: C901
f"Datetime parameter {search_request.datetime} is invalid."
) from e

next: Optional[str] = items.pop("next", None)
prev: Optional[str] = items.pop("prev", None)
# Starting in pgstac 0.9.0, the `next` and `prev` tokens are returned in spec-compliant links with method GET
next_from_link: Optional[str] = None
prev_from_link: Optional[str] = None
for link in items.get("links", []):
if link.get("rel") == "next":
next_from_link = link.get("href").split("token=next:")[1]
if link.get("rel") == "prev":
prev_from_link = link.get("href").split("token=prev:")[1]

next: Optional[str] = items.pop("next", next_from_link)
prev: Optional[str] = items.pop("prev", prev_from_link)
collection = ItemCollection(**items)

fields = getattr(search_request, "fields", None)
Expand Down
Loading