{"record":{"id":"0a847da6ce9e7128","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-requires-a-parent-cont","errorCode":null,"errorMessage":"template document tree plan requires a parent content operation","messagePattern":"template document tree plan requires a parent content operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":566,"sourceCode":"\tfor _, operation := range transaction.DoOperations {\n\t\tif nil == operation || \"\" == operation.ID {\n\t\t\treturn errors.New(\"template document tree plan contains an invalid parent operation\")\n\t\t}\n\t\tinverseAction, supported := inverseActions[operation.Action]\n\t\tif !supported || \"\" != operation.RootID {\n\t\t\treturn errors.New(\"template document tree plan contains an unsupported parent operation\")\n\t\t}\n\t\tif \"insert\" == operation.Action || \"delete\" == operation.Action || \"update\" == operation.Action {\n\t\t\thasContentMutation = true\n\t\t}\n\t\tkey := inverseAction + \"\\x00\" + operation.ID\n\t\tif 1 > undoOperations[key] {\n\t\t\treturn errors.New(\"template document tree plan parent operations are not reversible\")\n\t\t}\n\t\tundoOperations[key]--\n\t}\n\tif !hasContentMutation {\n\t\treturn errors.New(\"template document tree plan requires a parent content operation\")\n\t}\n\tfor _, count := range undoOperations {\n\t\tif 0 != count {\n\t\t\treturn errors.New(\"template document tree plan parent operations are not reversible\")\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc transactionTargetsTemplateRoot(transaction *Transaction, rootID, boxID string) bool {\n\tmatched := false\n\tfor operationSetIndex, operations := range [][]*Operation{transaction.DoOperations, transaction.UndoOperations} {\n\t\tfor _, operation := range operations {\n\t\t\tif nil == operation {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tids := []string{operation.ID}\n\t\t\tif \"insert\" == operation.Action {","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L548-L584","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Include at least one insert/delete/update operation in the parent transaction's DoOperations","If no content change is needed, do not attach a template doc-tree plan; create documents directly","Rework the flow so template child documents are attached alongside a genuine content edit of the root document"],"exampleFix":"// before: only attribute ops\nops.DoOperations = []*Operation{{Action: \"setAttrs\", ID: id}}\n// after: add a content mutation\nops.DoOperations = []*Operation{{Action: \"update\", ID: id, Data: newContent}}","handlingStrategy":"validation","validationCode":"hasContent := false\nfor _, op := range tx.DoOperations {\n    if op.Action == \"insert\" || op.Action == \"delete\" || op.Action == \"update\" {\n        hasContent = true\n    }\n}\nif !hasContent {\n    return errors.New(\"plan attachment needs a content mutation\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Attach plans only alongside real content edits (insert/delete/update)","Do not attach plans for fold-state-only or attrs-only transactions","Create documents directly when no content anchor exists"],"tags":["go","transaction","validation"],"backgroundTag":"invalid-argument-value","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"}