Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: bound OperationService billing requests (#37425)

Yufeng He47ee9f743535
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(