-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
Conversation
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.
🤔 one more PR/issue about root-path 😭 we extensively worked on this recently #221 which seemed to From experience, issues are usually do to miss configuration on the proxy side |
root_path
in pagination links
as much as I would like to fix all the issues in stac-fastapi, I'm still lacking replicable example of this. we do have k8s/aws lambda/azure deployments set up and the root-path duplication is usually found for mis configuration. can you tell a bit more about your environment? |
stac-fastapi-pgstac=5.0.2 environment = {
name = "My STAC API"
version = var.api_version
cors_origins = "*"
cachecontrol = "public, max-age=3600"
debug = "true"
POSTGRES_USER = local.database_username
POSTGRES_PASS = local.database_passwprd
POSTGRES_DBNAME = local.database_name
POSTGRES_HOST_READER = local.database_hostname
POSTGRES_HOST_WRITER = local.database_hostname
POSTGRES_PORT = local.database_port
ROOT_PATH = "/${local.stac_api_root_path}"
} I am not using the existing I will try |
I just tried with the existing Mangum handler: |
I've created https://github.com/developmentseed/stac-fastapi-root-path-lambda to try to replicate and I can't get the duplicate paths |
I think I was able to reproduce the error in these tests: Let me know if the test fixtures make sense. |
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 theROOT_PATH
already being part ofself.base_url
(derived fromget_base_url
) when joining it with the request path.The
BaseLinks.url
property instac_fastapi/pgstac/models/links.py
has been updated to ensure that the request path is made relative to thebase_url
's path component before joining. This prevents the duplication.A new test case,
test_pagination_link_with_root_path
, has been added totests/api/test_links.py
to specifically verify that pagination links are generated correctly whenROOT_PATH
is set.PR Checklist:
pre-commit
hooks pass locallymake test
)make docs
)