siyuan-note/siyuan · error

template document tree plan requires a parent content…

Error message

template document tree plan requires a parent content operation

What it means

After per-operation checks pass, the validator requires at least one content mutation (an insert, delete, or update do-operation) in the parent transaction. Fold/unfold and setAttrs operations alone are not considered content changes, so attaching a plan to a transaction that only toggles headings or attributes is rejected — the plan needs a real content anchor to attach its document-restoring operations to.

Solutions

  1. Include at least one insert/delete/update operation in the parent transaction's DoOperations
  2. If no content change is needed, do not attach a template doc-tree plan; create documents directly
  3. Rework the flow so template child documents are attached alongside a genuine content edit of the root document

Example fix

// before: only attribute ops
ops.DoOperations = []*Operation{{Action: "setAttrs", ID: id}}
// after: add a content mutation
ops.DoOperations = []*Operation{{Action: "update", ID: id, Data: newContent}}
Defensive patterns

Strategy: validation

Validate before calling

hasContent := false
for _, op := range tx.DoOperations {
    if op.Action == "insert" || op.Action == "delete" || op.Action == "update" {
        hasContent = true
    }
}
if !hasContent {
    return errors.New("plan attachment needs a content mutation")
}

Prevention

When it happens

Trigger: Calling AttachTemplateDocTreePlans with a parent transaction whose DoOperations contain only foldHeading/unfoldHeading or setAttrs operations (no insert/delete/update), even though they all have valid inverse undo entries.

Common situations: A UI flow that only changes fold state or attributes while still trying to instantiate template child documents; test code building transactions from non-content operations only.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/0a847da6ce9e7128. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_doc_tree.go:566

	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 {
		if 0 != count {
			return errors.New("template document tree plan parent operations are not reversible")
		}
	}
	return nil
}

func transactionTargetsTemplateRoot(transaction *Transaction, rootID, boxID string) bool {
	matched := false
	for operationSetIndex, operations := range [][]*Operation{transaction.DoOperations, transaction.UndoOperations} {
		for _, operation := range operations {
			if nil == operation {
				continue
			}
			ids := []string{operation.ID}
			if "insert" == operation.Action {

View on GitHub (pinned to 9f775e8a12)