{"record":{"id":"c891817a503497fb","repo":"twentyhq/twenty","slug":"failed-to-create-draft-version","errorCode":null,"errorMessage":"Failed to create draft version","messagePattern":"Failed to create draft version","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-front/src/modules/workflow/hooks/useGetUpdatableWorkflowVersionOrThrow.ts","lineNumber":31,"sourceCode":"  );\n  const workflow = useWorkflowWithCurrentVersion(workflowVisualizerWorkflowId);\n\n  const getUpdatableWorkflowVersion = async (): Promise<string> => {\n    if (!isDefined(workflowVisualizerWorkflowId) || !isDefined(workflow)) {\n      throw new Error('Failed to get updatable workflow version');\n    }\n\n    if (workflow.currentVersion.status === 'DRAFT') {\n      return workflow.currentVersion.id;\n    }\n\n    const draftVersionId = await createDraftFromWorkflowVersion({\n      workflowId: workflowVisualizerWorkflowId,\n      workflowVersionIdToCopy: workflow.currentVersion.id,\n    });\n\n    if (!isDefined(draftVersionId)) {\n      throw new Error('Failed to create draft version');\n    }\n\n    return draftVersionId;\n  };\n\n  return { getUpdatableWorkflowVersion };\n};\n","sourceCodeStart":13,"sourceCodeEnd":39,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/workflow/hooks/useGetUpdatableWorkflowVersionOrThrow.ts#L13-L39","documentation":"Thrown in useGetUpdatableWorkflowVersionOrThrow when the workflow's current version is not already a DRAFT, so it tries to create a draft copy via createDraftFromWorkflowVersion, but the returned draftVersionId is undefined. Editing a published workflow requires a draft; without one the edit flow cannot proceed.","triggerScenarios":"createDraftFromWorkflowVersion mutation fails or returns no id (permission denied, backend error, version already being edited elsewhere). The mutation resolved with errors but no id.","commonSituations":"User lacks edit permission on the workflow. Another user/session already holds the draft. Backend error during the copy. Network partial response.","solutions":["Inspect the createDraftFromWorkflowVersion response (data + errors) in DevTools.","Confirm the user has edit permission on the workflow and the workflow is not locked by another editor.","Reload the workflow to refresh currentVersion.status; if a DRAFT already exists it should be returned directly."],"exampleFix":"// before: if (!isDefined(draftVersionId)) { throw new Error('Failed to create draft version'); }\n// after:  if (!isDefined(draftVersionId)) {\n//           const err = draftErrors?.[0]?.message;\n//           throw new Error(err ?? 'Failed to create draft version');\n//         }","handlingStrategy":"try-catch","validationCode":"const canEditWorkflow = (workflow: { currentVersion: { status: string } } | null): boolean =>\n  isDefined(workflow) && (workflow.currentVersion.status === 'DRAFT' || true); // creation attempted if not draft","typeGuard":"const isDraftVersion = (status: string): boolean => status === 'DRAFT';","tryCatchPattern":"try {\n  await getUpdatableWorkflowVersion();\n} catch (e) {\n  if (/Failed to create draft version/.test((e as Error).message)) {\n    notifyUser('You may not have edit rights, or the workflow is locked by another editor.');\n  }\n}","preventionTips":["Refresh the workflow before editing to obtain an up-to-date currentVersion.status.","Confirm edit permission and that no other session holds the draft.","Have createDraftFromWorkflowVersion surface its mutation errors so this throw carries a real reason."],"tags":["workflow","graphql","apollo"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}