{"record":{"id":"7169e6c10b4d1c29","repo":"langgenius/dify","slug":"draft-workflow-not-exist-7169e6","errorCode":"draft_workflow_not_exist","errorMessage":"Draft workflow need to be initialized.","messagePattern":"Draft workflow need to be initialized\\.","errorType":"error_code","errorClass":"DraftWorkflowNotExist","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py","lineNumber":205,"sourceCode":"        console_ns.models[WorkflowResponse.__name__],\n    )\n    @console_ns.response(404, \"Draft workflow not found\")\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)\n    def get(self, pipeline: Pipeline):\n        \"\"\"\n        Get draft rag pipeline's workflow\n        \"\"\"\n        # fetch draft workflow by app_model\n        rag_pipeline_service = RagPipelineService(db.session())\n        workflow = rag_pipeline_service.get_draft_workflow(pipeline=pipeline)\n\n        if not workflow:\n            raise DraftWorkflowNotExist()\n\n        # return workflow, if not found, return 404\n        return dump_response(WorkflowResponse, workflow)\n\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @with_current_user\n    @get_rag_pipeline\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)\n    @console_ns.expect(console_ns.models[DraftWorkflowSyncPayload.__name__])\n    @console_ns.response(200, \"Success\", console_ns.models[RagPipelineWorkflowSyncResponse.__name__])\n    def post(self, current_user: Account, pipeline: Pipeline):\n        \"\"\"\n        Sync draft workflow\n        \"\"\"\n        content_type = request.headers.get(\"Content-Type\", \"\")","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py#L187-L223","documentation":"Returned (HTTP 404, `draft_workflow_not_exist`, 'Draft workflow need to be initialized.') by GET /rag/pipelines/<pipeline_id>/workflows/draft when `RagPipelineService.get_draft_workflow(pipeline)` is falsy. The draft workflow is the editable working copy of the pipeline graph; if it has never been created the endpoint cannot return one.","triggerScenarios":"Opening the pipeline editor for a brand-new pipeline before any graph has been synced; pipeline whose draft was deleted; restored/published-only pipeline that has no draft.","commonSituations":"Pipeline created via API without a follow-up draft sync. Database restore that omitted the workflows table. Multi-step onboarding that loads the editor before initialization.","solutions":["Initialize the draft via POST /rag/pipelines/<pipeline_id>/workflows/draft with the starter graph.","If a published workflow exists, POST /rag/pipelines/<pipeline_id>/workflows/<workflow_id>/restore to recreate the draft.","Handle 404 with code `draft_workflow_not_exist` in the client by showing an initialization screen.","Audit pipeline creation flows to ensure a draft is always seeded."],"exampleFix":"// before\nconst draft = await get(`/rag/pipelines/${pid}/workflows/draft`)\n// after\nlet draft = await get(`/rag/pipelines/${pid}/workflows/draft`).catch(e => {\n  if (e.code !== 'draft_workflow_not_exist') throw e\n  return null\n})\nif (!draft) {\n  await post(`/rag/pipelines/${pid}/workflows/draft`, { graph: emptyGraph })\n  draft = await get(`/rag/pipelines/${pid}/workflows/draft`)\n}","handlingStrategy":"try-catch","validationCode":"async function getOrInitDraft(pid) {\n  const r = await fetch(`/rag/pipelines/${pid}/workflows/draft`)\n  if (r.status === 404) {\n    await post(`/rag/pipelines/${pid}/workflows/draft`, { graph: starterGraph })\n    return fetch(`/rag/pipelines/${pid}/workflows/draft`).then(r => r.json())\n  }\n  if (!r.ok) throw new Error(`unexpected ${r.status}`)\n  return r.json()\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await get(`${base}/draft`)\n} catch (e) {\n  if (e.code === 'draft_workflow_not_exist') {\n    // initialize or restore-from-published, then retry once\n  } else throw e\n}","preventionTips":["Always create a draft workflow right after creating a pipeline.","Handle `draft_workflow_not_exist` in the client with an explicit initialization flow.","If a published workflow exists, prefer restore-to-draft over a blank draft."],"tags":["rag-pipeline","draft-workflow","not-found","precondition","api","rest"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}