{"record":{"id":"ce030393d08256c8","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-contains-an-unsupporte-ce0303","errorCode":null,"errorMessage":"template document tree plan contains an unsupported parent operation","messagePattern":"template document tree plan contains an unsupported parent operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":554,"sourceCode":"\tundoOperations := map[string]int{}\n\tfor _, operation := range transaction.UndoOperations {\n\t\tif nil == operation || \"\" == operation.ID {\n\t\t\treturn errors.New(\"template document tree plan contains an invalid parent undo operation\")\n\t\t}\n\t\tif _, supported := inverseActions[operation.Action]; !supported || \"\" != operation.RootID {\n\t\t\treturn errors.New(\"template document tree plan contains an unsupported parent undo operation\")\n\t\t}\n\t\tundoOperations[operation.Action+\"\\x00\"+operation.ID]++\n\t}\n\n\thasContentMutation := false\n\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}","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L536-L572","documentation":"Each do-operation's Action must be in the inverseActions whitelist (insert, delete, update, foldHeading, unfoldHeading, setAttrs) and its RootID must be empty. Actions without a defined inverse or root-scoped operations (non-empty RootID) cannot participate in the plan's reversibility accounting and are rejected as unsupported. The inverse action name is subsequently used to find the matching undo operation.","triggerScenarios":"Attaching a plan to a transaction whose DoOperations include an action outside the whitelist (e.g. moveBlock, append, plugin-defined actions) or a do operation with a non-empty RootID field.","commonSituations":"Combining template doc-tree attachment with root/document-level operations; frontend sending newer action types not yet mirrored in the kernel's inverse map; synthetic test transactions setting RootID.","solutions":["Restrict parent transaction operations to the whitelisted block-level actions","Ensure RootID is empty on parent do operations; run root-level work in a separate transaction","Update inverseActions in validateTemplateDocTreeParentOperations if a new action legitimately needs support"],"exampleFix":"// before\ndo := &Operation{Action: \"moveBlock\", ID: id, RootID: rootID}\n// after\ndo := &Operation{Action: \"update\", ID: id}","handlingStrategy":"validation","validationCode":"supported := map[string]bool{\"insert\": true, \"delete\": true, \"update\": true, \"foldHeading\": true, \"unfoldHeading\": true, \"setAttrs\": true}\nfor _, op := range tx.DoOperations {\n    if !supported[op.Action] || op.RootID != \"\" {\n        return errors.New(\"unsupported do action: \" + op.Action)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict parent transactions to insert/delete/update/fold/unfold/setAttrs","Never set RootID on parent do operations","Synchronize the inverseActions map when new actions are introduced"],"tags":["go","transaction","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}