Bug
InfrahubClient._graphql_url() interpolates the branch name directly into the URL path without percent-encoding it. Branch names containing URL-significant characters (#, /, …) therefore produce malformed URLs.
infrahub_sdk/client.py:
def _graphql_url(
self,
branch_name: str | None = None,
at: str | Timestamp | None = None,
) -> str:
url = f"{self.config.address}/graphql"
if branch_name:
url += f"/{branch_name}" # <-- not URL-encoded
url_params = {}
if at:
at = Timestamp(at)
url_params["at"] = at.to_string()
url += "?" + urlencode(url_params) # <-- query params ARE encoded
return url
The at query parameter is passed through urlencode, but the branch_name path segment is not.
Impact / symptoms
- A branch named e.g.
feature#123 builds https://<host>/graphql/feature#123. Everything after # is treated as a URL fragment, so the request path collapses to /graphql/feature → the wrong (or non-existent) branch is queried → URLNotFoundError / HTTP 404. When Infrahub tries to update that branch's commit, the operation fails.
- A branch named e.g.
feature/foo injects an extra path segment (/graphql/feature/foo), which likewise does not resolve.
Reported from the field (a customer hit both # and / cases and correctly suspected a general escaping problem).
Steps to reproduce
- Have (or create) an Infrahub branch whose name contains a
#, e.g. feature#123.
- Use the SDK against that branch (any call that routes through
_graphql_url, e.g. client.execute_graphql(branch_name="feature#123")).
- Observe the request goes to
/graphql/feature (fragment dropped) and returns a 404 / URLNotFoundError instead of hitting the intended branch.
Expected
The branch name should be percent-encoded as a single path segment so any branch name Infrahub accepts also works through the SDK.
Suggested fix
from urllib.parse import quote
...
if branch_name:
url += f"/{quote(branch_name, safe='')}"
(Apply the same treatment to the other places branch names are placed into paths, if any.)
Environment
- infrahub-sdk-python v1.22.0 (code path unchanged on
main @ HEAD 5b8047c).
Bug
InfrahubClient._graphql_url()interpolates the branch name directly into the URL path without percent-encoding it. Branch names containing URL-significant characters (#,/, …) therefore produce malformed URLs.infrahub_sdk/client.py:The
atquery parameter is passed throughurlencode, but thebranch_namepath segment is not.Impact / symptoms
feature#123buildshttps://<host>/graphql/feature#123. Everything after#is treated as a URL fragment, so the request path collapses to/graphql/feature→ the wrong (or non-existent) branch is queried →URLNotFoundError/ HTTP 404. When Infrahub tries to update that branch's commit, the operation fails.feature/fooinjects an extra path segment (/graphql/feature/foo), which likewise does not resolve.Reported from the field (a customer hit both
#and/cases and correctly suspected a general escaping problem).Steps to reproduce
#, e.g.feature#123._graphql_url, e.g.client.execute_graphql(branch_name="feature#123"))./graphql/feature(fragment dropped) and returns a 404 /URLNotFoundErrorinstead of hitting the intended branch.Expected
The branch name should be percent-encoded as a single path segment so any branch name Infrahub accepts also works through the SDK.
Suggested fix
(Apply the same treatment to the other places branch names are placed into paths, if any.)
Environment
main@ HEAD5b8047c).