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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: cannot delete workflow version if other version is published as a tool (#18486)
-LAN-2543162dec37
diff --git a/api/models/workflow.py b/api/models/workflow.pyindex 51f2f4cc9fb..5a67fa47a88 100644--- a/api/models/workflow.py+++ b/api/models/workflow.py@@ -245,6 +245,13 @@ class Workflow(Base):@propertydef tool_published(self) -> bool:+ """+ DEPRECATED: This property is not accurate for determining if a workflow is published as a tool.+ It only checks if there's a WorkflowToolProvider for the app, not if this specific workflow version+ is the one being used by the tool.++ For accurate checking, use a direct query with tenant_id, app_id, and version.+ """from models.tools import WorkflowToolProviderreturn (diff --git a/api/services/workflow_service.py b/api/services/workflow_service.pyindex b88c7b296df..5cd5c557466 100644--- a/api/services/workflow_service.py+++ b/api/services/workflow_service.py@@ -28,6 +28,7 @@ from extensions.ext_database import dbfrom models.account import Accountfrom models.enums import CreatedByRolefrom models.model import App, AppMode+from models.tools import WorkflowToolProviderfrom models.workflow import (Workflow,WorkflowNodeExecution,@@ -523,8 +524,19 @@ class WorkflowService:# Cannot delete a workflow that's currently in use by an appraise WorkflowInUseError(f"Cannot delete workflow that is currently in use by app '{app.name}'")- # Check if this workflow is published as a tool- if workflow.tool_published:+ # Don't use workflow.tool_published as it's not accurate for specific workflow versions+ # Check if there's a tool provider using this specific workflow version+ tool_provider = (+ session.query(WorkflowToolProvider)+ .filter(+ WorkflowToolProvider.tenant_id == workflow.tenant_id,+ WorkflowToolProvider.app_id == workflow.app_id,+ WorkflowToolProvider.version == workflow.version,+ )+ .first()+ )++ if tool_provider:# Cannot delete a workflow that's published as a toolraise WorkflowInUseError("Cannot delete workflow that is published as a tool")diff --git a/api/tests/unit_tests/services/workflow/test_workflow_deletion.py b/api/tests/unit_tests/services/workflow/test_workflow_deletion.pyindex 56efcccc78b..223020c2c51 100644--- a/api/tests/unit_tests/services/workflow/test_workflow_deletion.py+++ b/api/tests/unit_tests/services/workflow/test_workflow_deletion.py@@ -40,6 +40,10 @@ def workflow_setup():def test_delete_workflow_success(workflow_setup):# Setup mocks++ # Mock the tool provider query to return None (not published as a tool)+ workflow_setup["session"].query.return_value.filter.return_value.first.return_value = None+workflow_setup["session"].scalar = MagicMock(side_effect=[workflow_setup["workflow"], None]) # Return workflow first, then None for app@@ -97,7 +101,12 @@ def test_delete_workflow_in_use_by_app_error(workflow_setup):def test_delete_workflow_published_as_tool_error(workflow_setup):# Setup mocks- workflow_setup["workflow"].tool_published = True+ from models.tools import WorkflowToolProvider++ # Mock the tool provider query+ mock_tool_provider = MagicMock(spec=WorkflowToolProvider)+ workflow_setup["session"].query.return_value.filter.return_value.first.return_value = mock_tool_provider+workflow_setup["session"].scalar = MagicMock(side_effect=[workflow_setup["workflow"], None]) # Return workflow first, then None for app