Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): keep a path query string when the Python request adds params

Yudhi Armyndharisfb91e4dfdbb0
diff --git a/sdk/python/openwa/_http.py b/sdk/python/openwa/_http.py
index 2bf91346e..d9c312173 100644
--- a/sdk/python/openwa/_http.py
+++ b/sdk/python/openwa/_http.py
@@ -52,9 +52,8 @@ def build_url(base_url: str, path: str, query: Mapping[str, Any] | None = None)
params = {k: _serialize(v) for k, v in query.items() if v is not None}
if not params:
return url
- req = httpx.Request("GET", url, params=params)
- # httpx.Request already encoded params into the URL string.
- return str(req.url)
+ # Merge rather than pass params= to httpx.Request, which replaces a query already in the path.
+ return str(httpx.URL(url).copy_merge_params(params))
class HttpExecutor:
diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.py
index 5839a1fc1..87c1d2b84 100644
--- a/sdk/python/tests/test_sdk.py
+++ b/sdk/python/tests/test_sdk.py
@@ -149,6 +149,11 @@ class TestClientCore:
assert "sessionId" not in url
assert "None" not in url
+ def test_raw_request_keeps_a_query_string_in_the_path(self):
+ backend = MockBackend().on("GET", "/api/sessions", body=[])
+ make_client(backend).request("GET", "/api/sessions?limit=5", query={"name": "x"})
+ assert backend.last_call.url == "http://localhost:2785/api/sessions?limit=5&name=x"
+
def test_204_is_none(self):
# `delete` is declared `-> None`, so asserting on its result is a type error and proves
# nothing the signature does not already guarantee. What is worth asserting is that a 204