{"record":{"id":"5c64d53b712669e2","repo":"langgenius/dify","slug":"draft-workflow-not-exist-5c64d5","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_draft_variable.py","lineNumber":360,"sourceCode":"\n\n@console_ns.route(\"/rag/pipelines/<uuid:pipeline_id>/workflows/draft/environment-variables\")\nclass RagPipelineEnvironmentVariableCollectionApi(Resource):\n    @console_ns.response(\n        200,\n        \"Environment variables retrieved successfully\",\n        console_ns.models[EnvironmentVariableListResponse.__name__],\n    )\n    @_api_prerequisite\n    def get(self, _current_user: Account, pipeline: Pipeline):\n        \"\"\"\n        Get draft 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        if workflow is None:\n            raise DraftWorkflowNotExist()\n\n        env_vars = workflow.environment_variables\n        env_vars_list = []\n        for v in env_vars:\n            env_vars_list.append(\n                {\n                    \"id\": v.id,\n                    \"type\": \"env\",\n                    \"name\": v.name,\n                    \"description\": v.description,\n                    \"selector\": v.selector,\n                    \"value_type\": (\n                        environment_variable_value_type(v)\n                        if isinstance(v, LLMEnvironmentVariable)\n                        else v.value_type.value\n                    ),\n                    \"value\": v.value,\n                    # Do not track edited for env vars.","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py#L342-L378","documentation":"Returned (HTTP 404, error_code `draft_workflow_not_exist`, message 'Draft workflow need to be initialized.') by GET /rag/pipelines/<pipeline_id>/workflows/draft/environment-variables when no draft workflow exists for the pipeline. Environment variables live on the draft workflow entity, so without one there is nothing to enumerate.","triggerScenarios":"GET on environment-variables for a freshly-created pipeline whose draft has never been synced; for a pipeline whose draft workflow was deleted; before the first POST /workflows/draft has succeeded.","commonSituations":"Onboarding flow that loads the variables panel before the editor initializes the draft. Migration that left pipelines without drafts. UI deep-link directly to env vars on a new pipeline.","solutions":["Call POST /rag/pipelines/<pipeline_id>/workflows/draft with an initial graph to create the draft workflow.","Gate the environment-variables fetch behind a successful get-draft check.","In the UI, show an 'initialize workflow' prompt instead of crashing on 404.","If a published workflow exists, restore it to draft via .../workflows/<id>/restore."],"exampleFix":"// before\nconst envs = await get(`/rag/pipelines/${pid}/workflows/draft/environment-variables`)\n// after\nconst draft = await get(`/rag/pipelines/${pid}/workflows/draft`).catch(() => null)\nif (!draft) {\n  await post(`/rag/pipelines/${pid}/workflows/draft`, { graph: initialGraph })\n}\nconst envs = await get(`/rag/pipelines/${pid}/workflows/draft/environment-variables`)","handlingStrategy":"try-catch","validationCode":"// ensure draft exists before fetching env vars\nconst draft = await fetch(`/rag/pipelines/${pid}/workflows/draft`).then(r => r.ok ? r.json() : null)\nif (!draft) {\n  await post(`/rag/pipelines/${pid}/workflows/draft`, { graph: starterGraph })\n}\nconst envs = await fetch(`/rag/pipelines/${pid}/workflows/draft/environment-variables`).then(r => r.json())","typeGuard":null,"tryCatchPattern":"try {\n  return await get(`${base}/draft/environment-variables`)\n} catch (e) {\n  if (e.code === 'draft_workflow_not_exist') {\n    // initialize draft then retry once\n  } else throw e\n}","preventionTips":["Gate environment-variables fetch on a successful get-draft.","Show an initialization screen when draft_workflow_not_exist is returned.","Seed a draft workflow during pipeline creation."],"tags":["rag-pipeline","draft-workflow","not-found","environment-variables","precondition","api","rest"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}