{"record":{"id":"479c9f247ab8e80f","repo":"langgenius/dify","slug":"draft-workflow-not-found-pipeline-id-pipeline-id","errorCode":null,"errorMessage":"Draft workflow not found, pipeline_id={pipeline.id}","messagePattern":"Draft workflow not found, pipeline_id=(.+?)","errorType":"http","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py","lineNumber":303,"sourceCode":"        draft_var_srv.delete_variable(variable)\n        db.session.commit()\n        return Response(\"\", 204)\n\n\n@console_ns.route(\"/rag/pipelines/<uuid:pipeline_id>/workflows/draft/variables/<uuid:variable_id>/reset\")\nclass RagPipelineVariableResetApi(Resource):\n    @console_ns.response(200, \"Variable reset successfully\", workflow_draft_variable_model)\n    @console_ns.response(204, \"Variable reset (no content)\")\n    @_api_prerequisite\n    def put(self, _current_user: Account, pipeline: Pipeline, variable_id: UUID):\n        draft_var_srv = WorkflowDraftVariableService(\n            session=db.session(),\n        )\n\n        rag_pipeline_service = RagPipelineService(db.session())\n        draft_workflow = rag_pipeline_service.get_draft_workflow(pipeline=pipeline)\n        if draft_workflow is None:\n            raise NotFoundError(\n                f\"Draft workflow not found, pipeline_id={pipeline.id}\",\n            )\n        variable_id_str = str(variable_id)\n        variable = draft_var_srv.get_variable(variable_id=variable_id_str)\n        if variable is None:\n            raise NotFoundError(description=f\"variable not found, id={variable_id_str}\")\n        if variable.app_id != pipeline.id:\n            raise NotFoundError(description=f\"variable not found, id={variable_id_str}\")\n\n        resetted = draft_var_srv.reset_variable(draft_workflow, variable)\n        db.session.commit()\n        if resetted is None:\n            return Response(\"\", 204)\n        else:\n            return marshal(resetted, _WORKFLOW_DRAFT_VARIABLE_FIELDS)\n\n\ndef _get_variable_list(pipeline: Pipeline, node_id: str, current_user_id: str) -> WorkflowDraftVariableList:","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py#L285-L321","documentation":"Returned (HTTP 404, `not_found`) by PUT /rag/pipelines/<pipeline_id>/workflows/draft/variables/<variable_id>/reset when `RagPipelineService.get_draft_workflow(pipeline)` returns None. Reset requires a draft workflow graph to recompute the variable's default value, so a missing draft workflow is a hard precondition. Note this uses generic NotFoundError rather than the typed DraftWorkflowNotExist used elsewhere.","triggerScenarios":"Calling reset on a pipeline whose draft workflow was never created, was deleted, or whose initialization is still pending. Also triggered when the pipeline itself was just created and no draft has been synced yet via POST /workflows/draft.","commonSituations":"New pipeline that hasn't been initialized through the editor. Draft workflow deleted by an admin action. Race between pipeline creation and the first sync_draft_workflow call.","solutions":["Initialize the draft workflow first via POST /rag/pipelines/<pipeline_id>/workflows/draft with the graph payload.","Confirm with GET /rag/pipelines/<pipeline_id>/workflows/draft that a draft exists before exposing the reset action.","Disable the reset control in the UI until a draft workflow is present.","If the draft was intentionally removed, recreate it from the published workflow (restore endpoint) before reset."],"exampleFix":"// before\nawait put(`/rag/pipelines/${pid}/workflows/draft/variables/${vid}/reset`)\n// after\nconst draft = await getDraft(pid)\nif (!draft) {\n  await initDraft(pid, graphPayload) // POST /workflows/draft\n}\nawait put(`/rag/pipelines/${pid}/workflows/draft/variables/${vid}/reset`)","handlingStrategy":"validation","validationCode":"const draft = await fetch(`/rag/pipelines/${pid}/workflows/draft`).then(r => r.ok ? r.json() : null)\nif (!draft) {\n  // initialize or restore draft before reset\n  await post(`/rag/pipelines/${pid}/workflows/draft`, { graph: starterGraph })\n}\nawait put(`${base}/variables/${vid}/reset`)","typeGuard":null,"tryCatchPattern":"try {\n  await put(`${base}/variables/${vid}/reset`)\n} catch (e) {\n  if (e.status === 404 && /Draft workflow not found/.test(e.message)) {\n    // initialize draft, then retry once\n  } else throw e\n}","preventionTips":["Guarantee a draft workflow exists (GET .../workflows/draft returns 200) before exposing reset.","Disable the reset control until draft initialization completes.","If draft is missing, offer to restore from the published workflow."],"tags":["rag-pipeline","not-found","draft-workflow","precondition","api","rest"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}