fix: bound OperationService billing requests (#37425)

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
This commit is contained in:
Yufeng He 2026-06-22 14:45:03 +08:00 committed by GitHub
parent 762e7f7e8a
commit 47ee9f7435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -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()

View File

@ -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(