{"record":{"id":"dcf4b424b8e77782","repo":"langgenius/dify","slug":"str-e-dcf4b4","errorCode":null,"errorMessage":"{str(e)}","messagePattern":"\\{str\\(e\\)\\}","errorType":"http","errorClass":"WorkflowInUseError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py","lineNumber":788,"sourceCode":"    @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\n\n\n@console_ns.route(\"/rag/pipelines/<uuid:pipeline_id>/workflows/published/processing/parameters\")\nclass PublishedRagPipelineSecondStepApi(Resource):\n    @console_ns.doc(params=query_params_from_model(NodeIdQuery))\n    @console_ns.response(200, \"Success\", console_ns.models[RagPipelineStepParametersResponse.__name__])\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @get_rag_pipeline\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py#L770-L806","documentation":"HTTP 400 from `PipelineWorkflowItemApi.delete`'s `WorkflowInUseError` branch. After passing the active-binding guard, the handler calls `WorkflowService.delete_workflow`; if the workflow is still referenced by an app (per `WorkflowInUseError`, a `ValueError` subclass defined in `services/errors/workflow_service.py`), the message is re-emitted as `abort(400, description=str(e))`.","triggerScenarios":"DELETE on a published workflow version that is still referenced by some app (the service raises `WorkflowInUseError`). Distinct from the active-pipeline guard (946) — this fires when *any* app still depends on the workflow.","commonSituations":"Deleting a workflow version that an app still points at; deleting too early during a migration before apps were rebound; concurrent publish/delete race where another flow bound an app to the workflow.","solutions":["Find and rebind or remove apps referencing the workflow before retrying the delete.","Inspect `WorkflowInUseError`'s message (forwarded verbatim) to identify the referencing app.","Sequence migrations so app rebinding completes before workflow cleanup.","Retry idempotently after the referencing app is no longer bound."],"exampleFix":"# before\ndelete workflow -> 400 WorkflowInUseError: referenced by app <id>\n# after\n# 1. update the app's workflow_ref to a different version\n# 2. delete the now-unreferenced workflow","handlingStrategy":"try-catch","validationCode":"from services.workflow_service import WorkflowService\n\n# Before deleting, check whether any app references the workflow:\n# WorkflowInUseError is raised inside WorkflowService.delete_workflow,\n# so pre-check by listing apps bound to the workflow_ref.","typeGuard":null,"tryCatchPattern":"try:\n    client.delete(f\"/rag/pipelines/{pid}/workflows/{wid}\")\nexcept HTTPError as err:\n    if err.response.status_code == 400:\n        # message forwarded from WorkflowInUseError — rebind/remove referencing app, then retry\n        ...\n    raise","preventionTips":["Rebind or remove apps referencing a workflow before deleting it.","Read the forwarded message to find the referencing app id.","Sequence migrations so app rebinding completes before workflow cleanup.","Retry deletes idempotently after the dependency is cleared."],"tags":["workflow","rag-pipeline","referential-integrity","http-400"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}