From ab02f610e52b1f6f38b80bc8b6cd69d54b4d3e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E4=BF=8A=E7=94=B7?= Date: Tue, 13 Jan 2026 14:59:12 +0800 Subject: [PATCH] feat(workflow node): The execution records of the tool remove the foreign key that binds to the user, and directly store the user ID. --- api/app/core/workflow/nodes/tool/node.py | 6 ++++-- api/app/models/tool_model.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/app/core/workflow/nodes/tool/node.py b/api/app/core/workflow/nodes/tool/node.py index e1b5f380..6084dbe3 100644 --- a/api/app/core/workflow/nodes/tool/node.py +++ b/api/app/core/workflow/nodes/tool/node.py @@ -1,5 +1,6 @@ import logging import re +import uuid from typing import Any from app.core.workflow.nodes.base_node import BaseNode, WorkflowState @@ -24,10 +25,10 @@ class ToolNode(BaseNode): # 获取租户ID和用户ID tenant_id = self.get_variable("sys.tenant_id", state) user_id = self.get_variable("sys.user_id", state) + workspace_id = self.get_variable("sys.workspace_id", state) # 如果没有租户ID,尝试从工作流ID获取 if not tenant_id: - workspace_id = self.get_variable("sys.workspace_id", state) if workspace_id: from app.repositories.tool_repository import ToolRepository with get_db_read() as db: @@ -62,7 +63,8 @@ class ToolNode(BaseNode): tool_id=self.typed_config.tool_id, parameters=rendered_parameters, tenant_id=tenant_id, - user_id=user_id + user_id=uuid.UUID(user_id), + workspace_id=uuid.UUID(workspace_id) ) if result.success: diff --git a/api/app/models/tool_model.py b/api/app/models/tool_model.py index aec74ef7..ccd28693 100644 --- a/api/app/models/tool_model.py +++ b/api/app/models/tool_model.py @@ -211,12 +211,11 @@ class ToolExecution(Base): token_usage = Column(JSON) # 用户信息 - user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True) + user_id = Column(UUID(as_uuid=True), index=True, nullable=True) workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), nullable=False, index=True) # 关联关系 tool_config = relationship("ToolConfig", back_populates="executions") - user = relationship("User") workspace = relationship("Workspace") def __repr__(self):