siyuan-note/siyuan · error
template document tree parent snapshot is invalid
Error message
template document tree parent snapshot is invalid
What it means
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.
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
Defensive patterns
Strategy: validation
Validate before calling
if tree, _ := LoadTreeByBlockID(rootID); tree == nil { return errors.New("template root no longer exists") } Try / catch
if err := tx.Commit(); err != nil && strings.Contains(err.Error(), "template document tree parent snapshot is invalid") { re-renderTemplate(); retry() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- a document tree plan must be applied in a single transaction
- load template document tree parent snapshot failed
- template document tree plan contains an invalid document…
- template document tree plan does not match the edited…
- template document tree plan is invalid or has expired
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0d5bd12105af4ede.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/transaction.go:2700
if existingBox, exists := tx.restoredCreatedDocBoxes[operation.ID]; exists {
if existingBox != operation.Tree.Box {
tx.restoredCreatedDocBoxes[operation.ID] = ""
}
} else {
tx.restoredCreatedDocBoxes[operation.ID] = operation.Tree.Box
}
}
if ("restoreCreatedDoc" != operation.Action && "removeCreatedDoc" != operation.Action) ||
"" == operation.templateDocTreeRootID || nil == operation.Tree {
continue
}
if nil == tx.templateDocTreeRootSnapshot {
snapshot, loadErr := LoadTreeByBlockID(operation.templateDocTreeRootID)
if nil != loadErr {
return fmt.Errorf("load template document tree parent snapshot failed: %w", loadErr)
}
if nil == snapshot {
return errors.New("template document tree parent snapshot is invalid")
}
if nil != expectedTemplateDocTreeRoot &&
(expectedTemplateDocTreeRoot.ID != snapshot.ID || expectedTemplateDocTreeRoot.Box != snapshot.Box ||
expectedTemplateDocTreeRoot.Path != snapshot.Path || expectedTemplateDocTreeRoot.HPath != snapshot.HPath) {
return errors.New("the document used to render the template has changed")
}
tx.templateDocTreeRootSnapshot = snapshot
}
if nil == tx.templateDocTreeRootSnapshot || tx.templateDocTreeRootSnapshot.ID != operation.templateDocTreeRootID ||
tx.templateDocTreeRootSnapshot.Box != operation.Tree.Box {
return errors.New("template document tree parent snapshot is invalid")
}
}
tx.listItemFoldCandidates = nil
tx.listItemFoldCandidateIDs = map[string]struct{}{}
tx.deletedAttrViewBlockIDs = map[string]map[string]struct{}{}
tx.deletedAttrViewCarriers = map[string]string{}
tx.attributeViewDeletionUndo, tx.attributeViewDeletionErr = nil, nilView on GitHub (pinned to 9f775e8a12)