siyuan-note/siyuan · error
template document tree plan contains an invalid parent…
Error message
template document tree plan contains an invalid parent operation
What it means
The same validator checks each do-operation in the parent transaction: it must be non-nil and carry a non-empty ID. A nil pointer or blank ID makes the operation impossible to pair with its inverse undo entry, so the attachment aborts. This is the do-side counterpart of the 'invalid parent undo operation' check.
Solutions
- Ensure every DoOperations entry is non-nil with a populated ID
- Generate/assign IDs when constructing do operations, mirroring the undo entries
- Validate the transaction before attaching the plan
Example fix
// before
do := &Operation{Action: "insert", Data: md}
// after
do := &Operation{Action: "insert", Data: md, ID: util.TimeNSID()} Defensive patterns
Strategy: validation
Validate before calling
for _, op := range tx.DoOperations {
if op == nil || op.ID == "" {
return errors.New("do operation missing ID")
}
} Type guard
func hasValidDoOps(ops []*Operation) bool {
for _, op := range ops {
if op == nil || op.ID == "" {
return false
}
}
return true
} Prevention
- Generate IDs (e.g. util.TimeNSID) for every do operation
- Validate the transaction before calling AttachTemplateDocTreePlans
When it happens
Trigger: Calling AttachTemplateDocTreePlans with a transaction whose DoOperations slice contains a nil *Operation or an operation with an empty ID field, e.g. from hand-built or partially deserialized transactions.
Common situations: API/plugin code constructing transactions manually and forgetting IDs; payload deserialization dropping fields; test fixtures with synthetic do operations.
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 undo…
- 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/67f5caaad2c76f17.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:550
"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 = true
}
key := inverseAction + "\x00" + operation.ID
if 1 > undoOperations[key] {
return errors.New("template document tree plan parent operations are not reversible")
}
undoOperations[key]--
}
if !hasContentMutation {
return errors.New("template document tree plan requires a parent content operation")
}
for _, count := range undoOperations {View on GitHub (pinned to 9f775e8a12)