From 2020669cb045cd6da606dd9bbc7dfe59f0dfb717 Mon Sep 17 00:00:00 2001 From: L1nSn0w Date: Sat, 14 Feb 2026 14:23:02 +0800 Subject: [PATCH] feat(api): improve timeout handling in BaseRequest class Updated the BaseRequest class to conditionally include the timeout parameter when making requests with httpx. This change preserves the library's default timeout behavior by only passing the timeout argument when it is explicitly set, enhancing request management and flexibility. --- api/services/enterprise/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/services/enterprise/base.py b/api/services/enterprise/base.py index 8f7e6ed525..744b7992f8 100644 --- a/api/services/enterprise/base.py +++ b/api/services/enterprise/base.py @@ -56,7 +56,14 @@ class BaseRequest: logger.debug("Failed to generate traceparent header", exc_info=True) with httpx.Client(mounts=mounts) as client: - response = client.request(method, url, json=json, params=params, headers=headers, timeout=timeout) + # IMPORTANT: + # - In httpx, passing timeout=None disables timeouts (infinite) and overrides the library default. + # - To preserve httpx's default timeout behavior for existing call sites, only pass the kwarg when set. + request_kwargs: dict[str, Any] = {"json": json, "params": params, "headers": headers} + if timeout is not None: + request_kwargs["timeout"] = timeout + + response = client.request(method, url, **request_kwargs) if raise_for_status: response.raise_for_status() return response.json()