langgenius/dify · error

Cannot delete workflow that is currently in use by pipeline

Error message

Cannot delete workflow that is currently in use by pipeline '{pipeline.id}'

What it means

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.

Source

Thrown at api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py:776

            if not workflow:
                raise NotFound("Workflow not found")

            return dump_response(WorkflowResponse, workflow)

    @console_ns.response(204, "Workflow deleted successfully")
    @setup_required
    @login_required
    @account_initialization_required
    @edit_permission_required
    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)
    @get_rag_pipeline
    def delete(self, pipeline: Pipeline, workflow_id: str):
        """
        Delete a published workflow version that is not currently active on the pipeline.
        """
        if pipeline.workflow_id == workflow_id:
            abort(400, description=f"Cannot delete workflow that is currently in use by pipeline '{pipeline.id}'")

        workflow_service = WorkflowService()
        workflow_ref = WorkflowRefService.create_pipeline_workflow_ref(pipeline, workflow_id)

        with sessionmaker(db.engine).begin() as session:
            try:
                workflow_service.delete_workflow(
                    session=session,
                    workflow_ref=workflow_ref,
                )
            except WorkflowInUseError as e:
                abort(400, description=str(e))
            except DraftWorkflowDeletionError as e:
                abort(400, description=str(e))
            except ValueError as e:
                raise NotFound(str(e))

        return None, 204

View on GitHub (pinned to ef8544b173)

Solutions

  1. Publish or switch the pipeline to a different workflow before deleting the current one.
  2. If you want to remove the active workflow, delete/recreate the pipeline rather than the workflow binding.
  3. In the UI, hide or disable the delete control for the workflow whose id equals `pipeline.workflow_id`.
  4. Double-check the `workflow_id` path parameter — a stale value pointing at the active workflow produces this error.

Example fix

# before
delete /rag/pipelines/{pid}/workflows/{active_workflow_id}  # 400
# after
# 1. publish/switch pipeline to a new workflow version first
# 2. then delete the now-inactive workflow version
Defensive patterns

Strategy: validation

Validate before calling

def can_delete(pipeline_workflow_id: str, target_workflow_id: str) -> bool:
    return pipeline_workflow_id != target_workflow_id

# fetch pipeline first, then:
if not can_delete(pipeline.workflow_id, workflow_id):
    raise RuntimeError("switch pipeline to another workflow before deleting")

Type guard

def is_inactive_workflow(pipeline_workflow_id: str, target_id: str) -> bool:
    return pipeline_workflow_id != target_id

Try / catch

try:
    client.delete(f"/rag/pipelines/{pid}/workflows/{wid}")
except HTTPError as err:
    if err.response.status_code == 400 and "currently in use" in err.response.text:
        # switch pipeline to another workflow, then retry
        ...
    raise

Prevention

When it happens

Trigger: DELETE /console/api/datasets/rag/pipelines/<pipeline_id>/workflows/<workflow_id> where `<workflow_id>` equals the pipeline's currently bound `workflow_id`.

Common situations: 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.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/4901e94fb877d283. Report an issue: GitHub.