{"record":{"id":"0d5bd12105af4ede","repo":"siyuan-note/siyuan","slug":"template-document-tree-parent-snapshot-is-invalid","errorCode":null,"errorMessage":"template document tree parent snapshot is invalid","messagePattern":"template document tree parent snapshot is invalid","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/transaction.go","lineNumber":2700,"sourceCode":"\t\t\tif existingBox, exists := tx.restoredCreatedDocBoxes[operation.ID]; exists {\n\t\t\t\tif existingBox != operation.Tree.Box {\n\t\t\t\t\ttx.restoredCreatedDocBoxes[operation.ID] = \"\"\n\t\t\t\t}\n\t\t\t} else {\n\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.deletedAttrViewCarriers = map[string]string{}\n\ttx.attributeViewDeletionUndo, tx.attributeViewDeletionErr = nil, nil","sourceCodeStart":2682,"sourceCodeEnd":2718,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/transaction.go#L2682-L2718","documentation":"After loading, the template parent snapshot must be non-nil. LoadTreeByBlockID can return (nil, nil) when no tree is found without an error; this guard converts that silent miss into an explicit error so the transaction does not proceed with a nil snapshot.","triggerScenarios":"Committing a template-render operation whose templateDocTreeRootID cannot be resolved to any document tree — the root block ID does not exist in the repository index.","commonSituations":"The template's parent document was deleted concurrently; the block ID belongs to a different notebook that is closed or unmounted; stale IDs left over after doc re-creation (deleted and recreated docs get new IDs).","solutions":["Confirm the template document exists and its root block ID is current","Re-render the template from the live document to obtain a fresh root ID","Rebuild the index if blocktree.db is stale","Discard/reissue the stale transaction"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if tree, _ := LoadTreeByBlockID(rootID); tree == nil { return errors.New(\"template root no longer exists\") }","typeGuard":null,"tryCatchPattern":"if err := tx.Commit(); err != nil && strings.Contains(err.Error(), \"template document tree parent snapshot is invalid\") { re-renderTemplate(); retry() }","preventionTips":["Re-render templates to get fresh root IDs instead of caching them long-term","Check document existence before enqueueing template operations","Avoid referencing docs in closed/unmounted notebooks","Rebuild the index when blocktree lookups return empty"],"tags":["transaction","template","snapshot"],"backgroundTag":"resource-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}