{"record":{"id":"3e1df51429ae5d74","repo":"n8n-io/n8n","slug":"cannot-publish-archived-workflow","errorCode":null,"errorMessage":"Cannot publish archived Workflow","messagePattern":"Cannot publish archived Workflow","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/db/src/repositories/workflow.repository.ts","lineNumber":1532,"sourceCode":"\t}\n\n\t/**\n\t * Publish a specific version of a workflow\n\t * @param workflowId - The ID of the workflow\n\t * @param versionId - The ID of the version to publish (optional; if not provided, uses the current version)\n\t * */\n\tasync publishVersion(workflowId: string, versionId?: string) {\n\t\tconst workflow = await this.findOne({\n\t\t\twhere: { id: workflowId },\n\t\t\tselect: ['id', 'versionId', 'isArchived'],\n\t\t});\n\n\t\tif (!workflow) {\n\t\t\tthrow new UserError(`Workflow \"${workflowId}\" not found.`);\n\t\t}\n\n\t\tif (workflow.isArchived) {\n\t\t\tthrow new UserError('Cannot publish archived Workflow', {\n\t\t\t\textra: { workflowId },\n\t\t\t});\n\t\t}\n\n\t\tconst versionIdToPublish = versionId ?? workflow.versionId;\n\n\t\tconst version = await this.workflowHistoryRepository.findOneBy({\n\t\t\tworkflowId,\n\t\t\tversionId: versionIdToPublish,\n\t\t});\n\t\tif (!version) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Version \"${versionIdToPublish}\" not found for workflow \"${workflowId}\".`,\n\t\t\t);\n\t\t}\n\n\t\treturn await this.update(\n\t\t\t{ id: workflowId },","sourceCodeStart":1514,"sourceCodeEnd":1550,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/db/src/repositories/workflow.repository.ts#L1514-L1550","documentation":"UserError thrown by WorkflowRepository.publishVersion() when the workflow exists but has isArchived === true. Archived workflows are immutable and cannot be published; the error includes extra.{workflowId} for telemetry/debugging. Fires after the not-found check, before version lookup.","triggerScenarios":"Calling publishVersion on a workflow that was archived (soft-deleted out of the active set). The publish path refuses to promote a version of an archived workflow.","commonSituations":"A user opens an archived workflow from history/deep link and clicks publish; automation that re-publishes from a list without filtering archived; unarchiving not done before publish.","solutions":["Unarchive the workflow first, then publish: `await workflowRepo.update({ id }, { isArchived: false })`.","Filter archived workflows out of any bulk-publish job.","Surface a UI hint: 'This workflow is archived. Restore it before publishing a version.'","If archival was intentional and permanent, treat publish as an invalid action and do not expose the button."],"exampleFix":"// before\nawait workflowRepo.publishVersion(archivedId, versionId);\n\n// after\nawait workflowRepo.update({ id: archivedId }, { isArchived: false });\nawait workflowRepo.publishVersion(archivedId, versionId);","handlingStrategy":"validation","validationCode":"const wf = await workflowRepository.findOne({ where: { id: workflowId }, select: ['id', 'isArchived'] });\nif (!wf) { /* not found */ }\nif (wf.isArchived) { // unarchive first, or refuse to publish }","typeGuard":"function isPublishable(wf: { isArchived: boolean } | null): wf is { isArchived: false } {\n  return wf !== null && wf.isArchived === false;\n}","tryCatchPattern":"try {\n  await workflowRepository.publishVersion(workflowId, versionId);\n} catch (err) {\n  if (err instanceof UserError && /Cannot publish archived Workflow/.test(err.message)) {\n    // unarchive, then retry — or surface to user\n  } else throw err;\n}","preventionTips":["Filter archived workflows out of bulk publish operations.","Unarchive before publishing; surface the precondition in the UI.","Hide the publish control on archived workflows."],"tags":["workflow","archived","publish","repository"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}