{"record":{"id":"00465860ed85c4ad","repo":"langgenius/dify","slug":"workflow-not-found","errorCode":null,"errorMessage":"Workflow not found","messagePattern":"Workflow not found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/app/workflow.py","lineNumber":1610,"sourceCode":"            update_data[\"marked_comment\"] = args.marked_comment\n\n        if not update_data:\n            return {\"message\": \"No valid fields to update\"}, 400\n\n        workflow_service = WorkflowService()\n        workflow_ref = WorkflowRefService.create_app_workflow_ref(app_model, workflow_id)\n\n        # Create a session and manage the transaction\n        with sessionmaker(db.engine, expire_on_commit=False).begin() as session:\n            workflow = workflow_service.update_workflow(\n                session=session,\n                account_id=current_user.id,\n                data=update_data,\n                workflow_ref=workflow_ref,\n            )\n\n            if not workflow:\n                raise NotFound(\"Workflow not found\")\n\n            response = dump_response(WorkflowResponse, _WorkflowResponseSource(workflow, session=session))\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    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_EDIT)\n    @console_ns.response(204, \"Workflow deleted successfully\")\n    def delete(self, app_model: App, workflow_id: str):\n        \"\"\"\n        Delete workflow\n        \"\"\"\n        workflow_service = WorkflowService()\n        workflow_ref = WorkflowRefService.create_app_workflow_ref(app_model, workflow_id)","sourceCodeStart":1592,"sourceCodeEnd":1628,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L1592-L1628","documentation":"HTTP 404 NotFound('Workflow not found') raised by WorkflowByIdApi.patch (PATCH /apps/{app_id}/workflows/{workflow_id}) when WorkflowService.update_workflow returns a falsy workflow after the update transaction. The route resolves the path workflow_id via WorkflowRefService.create_app_workflow_ref; if no workflow matches that ref for the app, update returns None and the 404 fires.","triggerScenarios":"Patching marked_name/marked_comment on a workflow_id that does not exist for the app, was deleted, or whose ref does not resolve.","commonSituations":"Stale id kept by the client after the workflow was deleted/published; cross-app id; ref-lookup mismatch after a migration.","solutions":["Refresh the workflow list (GET /apps/{app_id}/workflows) and PATCH the correct existing id.","Confirm the workflow_id belongs to the same app_id.","If the workflow was deleted, recreate or restore it before patching."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the workflow id exists for this app before PATCH.\nconst exists = await listWorkflows(appId).then(list => list.some(w => w.id === workflowId));\nif (!exists) { refreshWorkflowList(); return; }","typeGuard":"const isWorkflowOfApp = (w, appId): boolean => !!w && w.app_id === appId;","tryCatchPattern":"try {\n  return await patchWorkflow(appId, workflowId, patch);\n} catch (e) {\n  if (e?.status === 404 && /Workflow not found/i.test(e?.message)) {\n    await refreshWorkflowList(); return;\n  }\n  throw e;\n}","preventionTips":["Refresh the workflow list before exposing edit actions.","Confirm the workflow_id belongs to the current app_id.","Disable the edit UI for ids that no longer appear in the list."],"tags":["workflow","not-found","update","console-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}