{"record":{"id":"7855538a0bb6725c","repo":"n8n-io/n8n","slug":"version-versionidtopublish-not-found-for-work","errorCode":null,"errorMessage":"Version \"${versionIdToPublish}\" not found for workflow \"${workflowId}\".","messagePattern":"Version \"(.+?)\" not found for workflow \"(.+?)\"\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/db/src/repositories/workflow.repository.ts","lineNumber":1544,"sourceCode":"\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 },\n\t\t\t{ active: true, activeVersionId: versionIdToPublish },\n\t\t);\n\t}\n\n\tasync unpublishAll() {\n\t\treturn await this.update(\n\t\t\t{ activeVersionId: Not(IsNull()) },\n\t\t\t{ active: false, activeVersionId: null },\n\t\t);\n\t}\n\n\tasync findByActiveState(activeState: boolean) {","sourceCodeStart":1526,"sourceCodeEnd":1562,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/db/src/repositories/workflow.repository.ts#L1526-L1562","documentation":"UserError thrown by WorkflowRepository.publishVersion() when the workflow exists and isn't archived, but the requested versionId (or the workflow's current versionId when none is supplied) has no matching row in workflowHistoryRepository. Means the version to publish isn't in history — either deleted, never saved, or mismatched.","triggerScenarios":"Calling publishVersion(workflowId, versionId) where versionId doesn't exist for that workflow; or omitting versionId when workflow.versionId itself is stale/missing from history. The findOneBy on (workflowId, versionIdToPublish) returns null.","commonSituations":"History retention purged old versions; a version ID copied from a different workflow; race where the version was pruned between read and publish; manual DB surgery that removed history rows; the workflow's current versionId predates history tracking.","solutions":["List available versions before publishing: `await workflowHistoryRepo.find({ where: { workflowId } })` and validate the chosen versionId.","Increase history retention if versions are being pruned too aggressively.","If publishing the current version, ensure workflow.versionId corresponds to an existing history row; re-save the workflow to materialize one if needed.","Never accept arbitrary version IDs from untrusted input without an existence check."],"exampleFix":"// before\nawait workflowRepo.publishVersion(workflowId, requestedVersionId);\n\n// after\nconst version = await workflowHistoryRepository.findOneBy({\n  workflowId,\n  versionId: requestedVersionId,\n});\nif (!version) throw new UserError(`Version '${requestedVersionId}' not in history for workflow '${workflowId}'`);\nawait workflowRepo.publishVersion(workflowId, requestedVersionId);","handlingStrategy":"validation","validationCode":"const version = await workflowHistoryRepository.findOneBy({ workflowId, versionId: requestedVersionId });\nif (!version) { // do not call publishVersion; surface 'version not in history' }","typeGuard":"async function versionInHistory(workflowId: string, versionId: string): Promise<boolean> {\n  return Boolean(await workflowHistoryRepository.existsBy({ workflowId, versionId }));\n}","tryCatchPattern":"try {\n  await workflowRepository.publishVersion(workflowId, versionId);\n} catch (err) {\n  if (err instanceof UserError && /Version .* not found for workflow/.test(err.message)) {\n    // list available versions and ask user to pick a valid one\n  } else throw err;\n}","preventionTips":["List available versions before letting users pick one to publish.","Tune history retention so publishable versions aren't pruned.","Never trust arbitrary version IDs from untrusted input without an existence check."],"tags":["workflow","version","not-found","history","publish"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}