{"record":{"id":"e97b1f9c0f297d4d","repo":"langgenius/dify","slug":"workflow-not-initialized","errorCode":null,"errorMessage":"Workflow not initialized","messagePattern":"Workflow not initialized","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/app/workflow.py","lineNumber":1236,"sourceCode":"    @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])\n    @with_current_user\n    @edit_permission_required\n    def post(self, current_user: Account, app_model: App, node_id: str):\n        \"\"\"\n        Run draft workflow node\n        \"\"\"\n        args_model = DraftWorkflowNodeRunPayload.model_validate(console_ns.payload or {})\n        args = args_model.model_dump(exclude_none=True)\n\n        user_inputs = args_model.inputs\n        if user_inputs is None:\n            raise ValueError(\"missing inputs\")\n\n        workflow_srv = WorkflowService()\n        # fetch draft workflow by app_model\n        draft_workflow = workflow_srv.get_draft_workflow(app_model=app_model, session=db.session())\n        if not draft_workflow:\n            raise ValueError(\"Workflow not initialized\")\n        files = _parse_file(draft_workflow, args.get(\"files\"))\n        workflow_service = WorkflowService()\n\n        workflow_node_execution = workflow_service.run_draft_workflow_node(\n            app_model=app_model,\n            draft_workflow=draft_workflow,\n            node_id=node_id,\n            user_inputs=user_inputs,\n            account=current_user,\n            query=args.get(\"query\", \"\"),\n            files=files,\n        )\n\n        return WorkflowRunNodeExecutionResponse.model_validate(\n            workflow_node_execution, from_attributes=True\n        ).model_dump(mode=\"json\")\n\n","sourceCodeStart":1218,"sourceCodeEnd":1254,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L1218-L1254","documentation":"Bare ValueError('Workflow not initialized') raised inside DraftWorkflowNodeRunApi.post (POST /apps/{app_id}/workflows/draft/nodes/{node_id}/run) when WorkflowService.get_draft_workflow returns None for the app. This means the app has no saved draft workflow graph yet, so no node can be run. The ValueError propagates uncaught and is returned as HTTP 400 'Workflow not initialized'.","triggerScenarios":"Calling the node-run endpoint on an app that has never had its workflow draft persisted (e.g. a freshly created app before any save), or whose draft was deleted.","commonSituations":"New workflow/advanced-chat app whose graph was never saved; the user opened the editor but never triggered an autosave/publish; data inconsistency after migration.","solutions":["Open the workflow editor and save the draft at least once before running a node.","Verify the app is in WORKFLOW or ADVANCED_CHAT mode and has a draft workflow row.","If the draft was deleted, recreate it by saving the graph in the editor."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm a draft workflow exists before allowing node-run.\nconst draft = await getDraftWorkflow(appId);\nif (!draft) { notifyUser('Save the workflow first'); return; }","typeGuard":"const hasDraft = (d): d is {id: string} => !!d && typeof d.id === 'string';","tryCatchPattern":"try {\n  return await runDraftNode(appId, nodeId, body);\n} catch (e) {\n  if (e?.status === 400 && /Workflow not initialized/i.test(e?.message)) {\n    promptSaveWorkflow(); return;\n  }\n  throw e;\n}","preventionTips":["Save the draft workflow before exposing the per-node run action.","Disable the run button in the UI until get_draft_workflow returns non-null.","After deleting a draft, force the user to recreate it before running nodes."],"tags":["workflow","draft","not-initialized","node-run","validation","console-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}