Skip to content

Commit 690f819

Browse files
authored
fix(client): do not escape url param with httpx > 0.28 (#1236)
1 parent 88a676c commit 690f819

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

langfuse/_client/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
_AgnosticContextManager,
2222
_agnosticcontextmanager,
2323
)
24+
from packaging.version import Version
2425

2526
from langfuse._client.attributes import LangfuseOtelSpanAttributes
2627
from langfuse._client.datasets import DatasetClient, DatasetItemClient
@@ -1709,7 +1710,7 @@ def get_dataset(
17091710

17101711
while True:
17111712
new_items = self.api.dataset_items.list(
1712-
dataset_name=self._url_encode(name),
1713+
dataset_name=self._url_encode(name, is_url_param=True),
17131714
page=page,
17141715
limit=fetch_items_page_size,
17151716
)
@@ -2261,7 +2262,14 @@ def update_prompt(
22612262

22622263
return updated_prompt
22632264

2264-
def _url_encode(self, url: str) -> str:
2265+
def _url_encode(self, url: str, *, is_url_param: Optional[bool] = False) -> str:
2266+
# httpx ≥ 0.28 does its own WHATWG-compliant quoting (eg. encodes bare
2267+
# “%”, “?”, “#”, “|”, … in query/path parts). Re-quoting here would
2268+
# double-encode, so we skip when the value is about to be sent straight
2269+
# to httpx (`is_url_param=True`) and the installed version is ≥ 0.28.
2270+
if is_url_param and Version(httpx.__version__) >= Version("0.28.0"):
2271+
return url
2272+
22652273
# urllib.parse.quote does not escape slashes "/" by default; we need to add safe="" to force escaping
22662274
# we need add safe="" to force escaping of slashes
22672275
# This is necessary for prompts in prompt folders

0 commit comments

Comments
 (0)