siyuan-note/siyuan · error
template document tree plan contains an invalid parent undo…
Error message
template document tree plan contains an invalid parent undo operation
What it means
validateTemplateDocTreeParentOperations requires each undo operation in the parent transaction to be non-nil and carry a non-empty ID. An undo operation with a nil pointer or blank operation ID cannot be matched against the transaction's do-operations, so the plan attachment is rejected. This guards the reversibility bookkeeping that pairs each do operation with its inverse undo operation.
Solutions
- Ensure every entry in UndoOperations is a non-nil *Operation with a populated ID
- Populate IDs when building undo operations in the same loop that creates do operations
- Validate the transaction payload before calling AttachTemplateDocTreePlans
Example fix
// before
undo := &Operation{Action: "delete"}
// after
undo := &Operation{Action: "delete", ID: op.ID} Defensive patterns
Strategy: validation
Validate before calling
for _, op := range tx.UndoOperations {
if op == nil || op.ID == "" {
return errors.New("undo operation missing ID")
}
} Type guard
func hasValidUndoOps(ops []*Operation) bool {
for _, op := range ops {
if op == nil || op.ID == "" {
return false
}
}
return true
} Prevention
- Always set IDs when constructing undo operations
- Build do/undo pairs in the same helper function
- Validate transactions before attaching plans
When it happens
Trigger: Attaching a template doc-tree plan to a transaction whose UndoOperations slice contains a nil *Operation or an operation with an empty ID field, e.g. when the caller built undo entries manually or deserialized them from an incomplete payload.
Common situations: Programmatic/API construction of transactions with partially filled operations; a serialization round-trip that dropped the ID field; test code assembling synthetic transactions without IDs.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- template document tree plan contains an invalid document…
- template document tree plan contains an invalid parent…
- template document tree plan requires a parent content…
- all asset mappings failed
- assetPath is not an image referenced by the document
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/df4635a7846f0417.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:539
templateDocTreeRootID: plan.rootID,
})
}
return true, nil
}
func validateTemplateDocTreeParentOperations(transaction *Transaction) error {
inverseActions := map[string]string{
"insert": "delete",
"delete": "insert",
"update": "update",
"foldHeading": "unfoldHeading",
"unfoldHeading": "foldHeading",
"setAttrs": "setAttrs",
}
undoOperations := map[string]int{}
for _, operation := range transaction.UndoOperations {
if nil == operation || "" == operation.ID {
return errors.New("template document tree plan contains an invalid parent undo operation")
}
if _, supported := inverseActions[operation.Action]; !supported || "" != operation.RootID {
return errors.New("template document tree plan contains an unsupported parent undo operation")
}
undoOperations[operation.Action+"\x00"+operation.ID]++
}
hasContentMutation := false
for _, operation := range transaction.DoOperations {
if nil == operation || "" == operation.ID {
return errors.New("template document tree plan contains an invalid parent operation")
}
inverseAction, supported := inverseActions[operation.Action]
if !supported || "" != operation.RootID {
return errors.New("template document tree plan contains an unsupported parent operation")
}
if "insert" == operation.Action || "delete" == operation.Action || "update" == operation.Action {
hasContentMutation = trueView on GitHub (pinned to 9f775e8a12)