Skip to content

Commit b91b441

Browse files
committed
fix: Return the link to the connection pool after the node execution is completed
1 parent e23d413 commit b91b441

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

apps/application/flow/step_node/tool_lib_node/i_tool_lib_node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
from typing import Type
1010

11+
from django.db import connection
1112
from django.db.models import QuerySet
1213
from django.utils.translation import gettext_lazy as _
1314
from rest_framework import serializers
@@ -31,6 +32,8 @@ class FunctionLibNodeParamsSerializer(serializers.Serializer):
3132
def is_valid(self, *, raise_exception=False):
3233
super().is_valid(raise_exception=True)
3334
f_lib = QuerySet(Tool).filter(id=self.data.get('tool_lib_id')).first()
35+
# 归还链接到连接池
36+
connection.close()
3437
if f_lib is None:
3538
raise Exception(_('The function has been deleted'))
3639

apps/application/flow/workflow_manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from functools import reduce
1515
from typing import List, Dict
1616

17-
from django.db import close_old_connections
17+
from django.db import close_old_connections, connection
1818
from django.utils import translation
1919
from django.utils.translation import get_language
2020
from langchain_core.prompts import PromptTemplate
@@ -433,6 +433,8 @@ def hand_event_node_result(self, current_node, node_result_future):
433433
return None
434434
finally:
435435
current_node.node_chunk.end()
436+
# 归还链接到连接池
437+
connection.close()
436438

437439
def run_node_async(self, node):
438440
future = executor.submit(self.run_node, node)

apps/models_provider/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def is_valid_credential(provider, model_type, model_name, model_credential: Dict
106106

107107
def get_model_by_id(_id, workspace_id):
108108
model = QuerySet(Model).filter(id=_id).first()
109+
# 归还链接到连接池
110+
connection.close()
109111
get_authorized_model = DatabaseModelManage.get_model("get_authorized_model")
110112
if model and model.workspace_id != workspace_id and get_authorized_model is not None:
111113
model = get_authorized_model(QuerySet(Model).filter(id=_id), workspace_id).first()

0 commit comments

Comments
 (0)