{"record":{"id":"4901e94fb877d283","repo":"langgenius/dify","slug":"cannot-delete-workflow-that-is-currently-in-use-by","errorCode":null,"errorMessage":"Cannot delete workflow that is currently in use by pipeline '{pipeline.id}'","messagePattern":"Cannot delete workflow that is currently in use by pipeline '(.+?)'","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py","lineNumber":776,"sourceCode":"\n            if not workflow:\n                raise NotFound(\"Workflow not found\")\n\n            return dump_response(WorkflowResponse, workflow)\n\n    @console_ns.response(204, \"Workflow deleted successfully\")\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)\n    @get_rag_pipeline\n    def delete(self, pipeline: Pipeline, workflow_id: str):\n        \"\"\"\n        Delete a published workflow version that is not currently active on the pipeline.\n        \"\"\"\n        if pipeline.workflow_id == workflow_id:\n            abort(400, description=f\"Cannot delete workflow that is currently in use by pipeline '{pipeline.id}'\")\n\n        workflow_service = WorkflowService()\n        workflow_ref = WorkflowRefService.create_pipeline_workflow_ref(pipeline, workflow_id)\n\n        with sessionmaker(db.engine).begin() as session:\n            try:\n                workflow_service.delete_workflow(\n                    session=session,\n                    workflow_ref=workflow_ref,\n                )\n            except WorkflowInUseError as e:\n                abort(400, description=str(e))\n            except DraftWorkflowDeletionError as e:\n                abort(400, description=str(e))\n            except ValueError as e:\n                raise NotFound(str(e))\n\n        return None, 204","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py#L758-L794","documentation":"HTTP 400 from `PipelineWorkflowItemApi.delete`. Before delegating to `WorkflowService.delete_workflow`, the handler guards the active binding: if `pipeline.workflow_id == workflow_id`, it aborts with `Cannot delete workflow that is currently in use by pipeline '<pipeline_id>'`. You cannot delete the workflow that is currently published/active on the pipeline.","triggerScenarios":"DELETE /console/api/datasets/rag/pipelines/<pipeline_id>/workflows/<workflow_id> where `<workflow_id>` equals the pipeline's currently bound `workflow_id`.","commonSituations":"Attempting to delete the live/published workflow instead of a draft or older version; UI showing a 'delete' action on the active version; trying to clean up after a publish without first switching the pipeline to a different workflow.","solutions":["Publish or switch the pipeline to a different workflow before deleting the current one.","If you want to remove the active workflow, delete/recreate the pipeline rather than the workflow binding.","In the UI, hide or disable the delete control for the workflow whose id equals `pipeline.workflow_id`.","Double-check the `workflow_id` path parameter — a stale value pointing at the active workflow produces this error."],"exampleFix":"# before\ndelete /rag/pipelines/{pid}/workflows/{active_workflow_id}  # 400\n# after\n# 1. publish/switch pipeline to a new workflow version first\n# 2. then delete the now-inactive workflow version","handlingStrategy":"validation","validationCode":"def can_delete(pipeline_workflow_id: str, target_workflow_id: str) -> bool:\n    return pipeline_workflow_id != target_workflow_id\n\n# fetch pipeline first, then:\nif not can_delete(pipeline.workflow_id, workflow_id):\n    raise RuntimeError(\"switch pipeline to another workflow before deleting\")","typeGuard":"def is_inactive_workflow(pipeline_workflow_id: str, target_id: str) -> bool:\n    return pipeline_workflow_id != target_id","tryCatchPattern":"try:\n    client.delete(f\"/rag/pipelines/{pid}/workflows/{wid}\")\nexcept HTTPError as err:\n    if err.response.status_code == 400 and \"currently in use\" in err.response.text:\n        # switch pipeline to another workflow, then retry\n        ...\n    raise","preventionTips":["Never expose a delete control for the active workflow binding.","Publish/switch the pipeline to another version before deleting the current one.","Compare workflow_id against pipeline.workflow_id before issuing DELETE.","For full cleanup, delete the pipeline rather than its active workflow."],"tags":["workflow","rag-pipeline","state-conflict","http-400"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}