|
21 | 21 | _AgnosticContextManager, |
22 | 22 | _agnosticcontextmanager, |
23 | 23 | ) |
| 24 | +from packaging.version import Version |
24 | 25 |
|
25 | 26 | from langfuse._client.attributes import LangfuseOtelSpanAttributes |
26 | 27 | from langfuse._client.datasets import DatasetClient, DatasetItemClient |
@@ -1709,7 +1710,7 @@ def get_dataset( |
1709 | 1710 |
|
1710 | 1711 | while True: |
1711 | 1712 | 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), |
1713 | 1714 | page=page, |
1714 | 1715 | limit=fetch_items_page_size, |
1715 | 1716 | ) |
@@ -2261,7 +2262,14 @@ def update_prompt( |
2261 | 2262 |
|
2262 | 2263 | return updated_prompt |
2263 | 2264 |
|
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 | + |
2265 | 2273 | # urllib.parse.quote does not escape slashes "/" by default; we need to add safe="" to force escaping |
2266 | 2274 | # we need add safe="" to force escaping of slashes |
2267 | 2275 | # This is necessary for prompts in prompt folders |
|
0 commit comments