From 1523098a351bd2a53b81afb7a5ffc34ae6fb2b4e Mon Sep 17 00:00:00 2001 From: -LAN- Date: Fri, 30 May 2025 06:53:38 +0800 Subject: [PATCH] fix: Ensure tenant association for service accounts Signed-off-by: -LAN- --- api/core/ops/langfuse_trace/langfuse_trace.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/core/ops/langfuse_trace/langfuse_trace.py b/api/core/ops/langfuse_trace/langfuse_trace.py index 120c36f53d..fa1c6b4557 100644 --- a/api/core/ops/langfuse_trace/langfuse_trace.py +++ b/api/core/ops/langfuse_trace/langfuse_trace.py @@ -32,6 +32,7 @@ from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository from core.workflow.nodes.enums import NodeType from extensions.ext_database import db from models import Account, App, EndUser, WorkflowNodeExecutionTriggeredFrom +from models.account import TenantAccountJoin logger = logging.getLogger(__name__) @@ -130,6 +131,12 @@ class LangFuseDataTrace(BaseTraceInstance): service_account = session.query(Account).filter(Account.id == app.created_by).first() if not service_account: raise ValueError(f"Creator account with id {app.created_by} not found for app {app_id}") + current_tenant = ( + session.query(TenantAccountJoin).filter_by(account_id=service_account.id, current=True).first() + ) + if not current_tenant: + raise ValueError(f"Current tenant not found for account {service_account.id}") + service_account.set_tenant_id(current_tenant.tenant_id) workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository( session_factory=session_factory,