{"record":{"id":"cffb7ed3a2983871","repo":"siyuan-note/siyuan","slug":"the-document-used-to-render-the-template-has-chang-cffb7e","errorCode":null,"errorMessage":"the document used to render the template has changed","messagePattern":"the document used to render the template has changed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/transaction.go","lineNumber":2629,"sourceCode":"\t\t\t\ttx.restoredCreatedDocBoxes[operation.ID] = operation.Tree.Box\n\t\t\t}\n\t\t}\n\t\tif (\"restoreCreatedDoc\" != operation.Action && \"removeCreatedDoc\" != operation.Action) ||\n\t\t\t\"\" == operation.templateDocTreeRootID || nil == operation.Tree {\n\t\t\tcontinue\n\t\t}\n\t\tif nil == tx.templateDocTreeRootSnapshot {\n\t\t\tsnapshot, loadErr := LoadTreeByBlockID(operation.templateDocTreeRootID)\n\t\t\tif nil != loadErr {\n\t\t\t\treturn fmt.Errorf(\"load template document tree parent snapshot failed: %w\", loadErr)\n\t\t\t}\n\t\t\tif nil == snapshot {\n\t\t\t\treturn errors.New(\"template document tree parent snapshot is invalid\")\n\t\t\t}\n\t\t\tif nil != expectedTemplateDocTreeRoot &&\n\t\t\t\t(expectedTemplateDocTreeRoot.ID != snapshot.ID || expectedTemplateDocTreeRoot.Box != snapshot.Box ||\n\t\t\t\t\texpectedTemplateDocTreeRoot.Path != snapshot.Path || expectedTemplateDocTreeRoot.HPath != snapshot.HPath) {\n\t\t\t\treturn errors.New(\"the document used to render the template has changed\")\n\t\t\t}\n\t\t\ttx.templateDocTreeRootSnapshot = snapshot\n\t\t}\n\t\tif nil == tx.templateDocTreeRootSnapshot || tx.templateDocTreeRootSnapshot.ID != operation.templateDocTreeRootID ||\n\t\t\ttx.templateDocTreeRootSnapshot.Box != operation.Tree.Box {\n\t\t\treturn errors.New(\"template document tree parent snapshot is invalid\")\n\t\t}\n\t}\n\ttx.listItemFoldCandidates = nil\n\ttx.listItemFoldCandidateIDs = map[string]struct{}{}\n\ttx.deletedAttrViewBlockIDs = map[string]map[string]struct{}{}\n\ttx.structureCheckNodes = map[*ast.Node]struct{}{}\n\ttx.crossTreeMoveRefRefreshes = nil\n\ttx.luteEngine = util.NewLute()\n\ttx.m.Lock()\n\ttx.state.Store(1)\n\treturn\n}","sourceCodeStart":2611,"sourceCodeEnd":2647,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/transaction.go#L2611-L2647","documentation":"A transaction creating a document from a template records the parent document tree state expected at render time. At commit, the freshly loaded snapshot is compared (ID, Box, Path, HPath) against that expectation; if any differ, the underlying document was moved, renamed, or replaced while the transaction was being built, so the commit is refused to avoid writing into an inconsistent location.","triggerScenarios":"Committing a template-created-doc transaction whose expectedTemplateDocTreeRoot (ID/Box/Path/HPath) no longer matches the current on-disk parent tree — the parent doc was renamed, moved to another notebook, or its path changed between render and commit.","commonSituations":"User renames the parent document or drags it to another notebook while the template insertion is pending; sync applies a remote rename to the same document; two windows have divergent views of the same doc.","solutions":["Refresh the document tree in the UI and retry the template insertion against the current state","Avoid renaming/moving the parent document while a template-based creation is pending","Check sync history to see if a remote change moved the document, then re-perform the action on the moved document"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const cur = await fetchPost('/api/filetree/getDoc', {id: expectedRootId});\nif (cur.data.path !== expectedPath || cur.data.box !== expectedBox) {\n  throw new Error('parent document has moved; refresh before inserting template');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await insertTemplateDoc(parentId, tpl);\n} catch (e) {\n  if (String(e.message).includes('document used to render the template has changed')) {\n    await reloadDocTree();\n    await insertTemplateDoc(currentParentId, tpl); // retry with current parent\n  } else { throw e; }\n}","preventionTips":["Do not rename or move the parent document while a template insertion is in progress","Pause/complete sync before batch template operations","Perform one template operation at a time from the current UI state"],"tags":["transaction","templates","concurrent-modification"],"backgroundTag":"invalid-state-transition","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}