Skip to content

Fix: Prevent duplicate root_path in pagination links #250

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fabito
Copy link

@fabito fabito commented Jun 14, 2025

When a custom ROOT_PATH environment variable is used, the "next" pagination link could incorrectly include the root_path twice.

This was because the BaseLinks.url property, which generates the base for these links, did not properly account for the ROOT_PATH already being part of self.base_url (derived from get_base_url) when joining it with the request path.

The BaseLinks.url property in stac_fastapi/pgstac/models/links.py has been updated to ensure that the request path is made relative to the base_url's path component before joining. This prevents the duplication.

A new test case, test_pagination_link_with_root_path, has been added to tests/api/test_links.py to specifically verify that pagination links are generated correctly when ROOT_PATH is set.

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

When a custom `ROOT_PATH` environment variable is used, the "next"
pagination link could incorrectly include the root_path twice.

This was because the `BaseLinks.url` property, which generates the
base for these links, did not properly account for the `ROOT_PATH`
already being part of `self.base_url` (derived from `get_base_url`)
when joining it with the request path.

The `BaseLinks.url` property in `stac_fastapi/pgstac/models/links.py`
has been updated to ensure that the request path is made relative
to the `base_url`'s path component before joining. This prevents
the duplication.

A new test case, `test_pagination_link_with_root_path`, has been
added to `tests/api/test_links.py` to specifically verify that
pagination links are generated correctly when `ROOT_PATH` is set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant