From 47ee9f7435355b7138430ca7105738457954e93d Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Mon, 22 Jun 2026 14:45:03 +0800 Subject: [PATCH] fix: bound OperationService billing requests (#37425) Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: QuantumGhost --- api/services/operation_service.py | 6 +++++- api/tests/unit_tests/services/test_operation_service.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/services/operation_service.py b/api/services/operation_service.py index 903efd26ae7..6869cf23ea2 100644 --- a/api/services/operation_service.py +++ b/api/services/operation_service.py @@ -3,6 +3,8 @@ from typing import TypedDict import httpx +OPERATION_REQUEST_TIMEOUT = httpx.Timeout(10.0, connect=3.0) + class UtmInfo(TypedDict, total=False): """Expected shape of the utm_info dict passed to record_utm. @@ -26,7 +28,9 @@ class OperationService: headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key} url = f"{cls.base_url}{endpoint}" - response = httpx.request(method, url, json=json, params=params, headers=headers) + response = httpx.request( + method, url, json=json, params=params, headers=headers, timeout=OPERATION_REQUEST_TIMEOUT + ) return response.json() diff --git a/api/tests/unit_tests/services/test_operation_service.py b/api/tests/unit_tests/services/test_operation_service.py index e43a7fa649e..dffded658eb 100644 --- a/api/tests/unit_tests/services/test_operation_service.py +++ b/api/tests/unit_tests/services/test_operation_service.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch import httpx import pytest -from services.operation_service import OperationService +from services.operation_service import OPERATION_REQUEST_TIMEOUT, OperationService class TestOperationService: @@ -44,6 +44,7 @@ class TestOperationService: assert kwargs["json"] == json_data assert kwargs["headers"]["Billing-Api-Secret-Key"] == "s3cr3t" assert kwargs["headers"]["Content-Type"] == "application/json" + assert kwargs["timeout"] == OPERATION_REQUEST_TIMEOUT @patch("httpx.request") def test_should_propagate_httpx_error_when__send_request_raises(