{"record":{"id":"2af4b9e98de3c341","repo":"langgenius/dify","slug":"draft-workflow-not-exist","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":"warning","filePath":"api/controllers/console/app/workflow.py","lineNumber":590,"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    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_VIEW_LAYOUT)\n    @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])\n    def get(self, app_model: App):\n        \"\"\"\n        Get draft workflow\n        \"\"\"\n        # fetch draft workflow by app_model\n        workflow_service = WorkflowService()\n        workflow = workflow_service.get_draft_workflow(app_model=app_model, session=db.session())\n\n        if not workflow:\n            raise DraftWorkflowNotExist()\n\n        from services.agent.workflow_publish_service import WorkflowAgentPublishService\n\n        # Return workflow with response-only Agent node job projection so the\n        # front-end can treat draft graph node data as the editing source.\n        response = WorkflowResponse.model_validate(workflow, from_attributes=True).model_dump(mode=\"json\")\n        response[\"graph\"] = WorkflowAgentPublishService.project_draft_bindings_to_graph(\n            session=db.session(),\n            draft_workflow=workflow,\n        )\n        return response\n\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])\n    @console_ns.doc(\"sync_draft_workflow\")\n    @console_ns.doc(description=\"Sync draft workflow configuration\")","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L572-L608","documentation":"Raised as DraftWorkflowNotExist in DraftWorkflowApi.get when WorkflowService.get_draft_workflow returns None (api/controllers/console/app/workflow.py:589-590). The app has no draft workflow row — the workflow has not been initialized. Only applies to ADVANCED_CHAT and WORKFLOW mode apps (enforced by the @get_app_model decorator).","triggerScenarios":"GET /apps/{app_id}/workflows/draft for an ADVANCED_CHAT/WORKFLOW app that has never had its draft workflow created, or whose draft was deleted. The front-end typically calls this on app open.","commonSituations":"Newly created advanced-chat/workflow app before first save; draft workflow row removed by cleanup/migration; app imported without its workflow; race where the app exists but workflow init has not run.","solutions":["Initialize the draft workflow by saving the workflow graph once (POST /apps/{app_id}/workflows/draft).","If using the app-creation flow, ensure it bootstraps a draft workflow for ADVANCED_CHAT/WORKFLOW modes.","Check the workflows table for the app_id; if missing, run the workflow-init step.","Refresh the app after initialization."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Initialize a draft workflow if GET returns 404\nasync function loadOrInitDraft(appId) {\n  try { return await getDraftWorkflow(appId) }\n  catch (e) { if (e.code === 'draft_workflow_not_exist') return await initDraftWorkflow(appId); throw e }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getDraftWorkflow(appId)\n} catch (e) {\n  if (e.code === 'draft_workflow_not_exist') { await initDraftWorkflow(appId); return getDraftWorkflow(appId) }\n  throw e\n}","preventionTips":["Run workflow init as part of ADVANCED_CHAT/WORKFLOW app creation.","Handle 404 by initializing, not by erroring to the user."],"tags":["workflow","draft","not-exist","api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}