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
13 changes: 10 additions & 3 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- {python: '3.12', pypgstac: '0.9.*'}
- {python: '3.12', pypgstac: '0.8.*'}
- {python: '3.11', pypgstac: '0.8.*'}
- {python: '3.9', pypgstac: '0.8.*'}
- {python: '3.8', pypgstac: '0.8.*'}

timeout-minutes: 20

steps:
Expand All @@ -22,12 +28,12 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: setup.py

- name: Lint code
if: ${{ matrix.python-version == 3.11 }}
if: ${{ matrix.python == 3.11 }}
run: |
python -m pip install pre-commit
pre-commit run --all-files
Expand All @@ -39,6 +45,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[dev,server]
python -m pip install "pypgstac==${{ matrix.pypgstac }}"

- name: Run test suite
run: python -m pytest --cov stac_fastapi.pgstac --cov-report xml --cov-report term-missing
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
## [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)
- Add collection search extension ([#139](https://github.com/stac-utils/stac-fastapi-pgstac/pull/139))
- keep `/search` and `/collections` extensions separate ([#158](https://github.com/stac-utils/stac-fastapi-pgstac/pull/158))
- Fix `filter` extension implementation in `CoreCrudClient`
- update `pypgstac` requirement to `>=0.8,<0.10`
- set `pypgstac==0.9.*` for test requirements

## [3.0.0] - 2024-08-02

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:

database:
container_name: stac-db
image: ghcr.io/stac-utils/pgstac:v0.8.5
image: ghcr.io/stac-utils/pgstac:v0.9.1
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
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 @@ -244,8 +244,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