{"record":{"id":"67f5caaad2c76f17","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-contains-an-invalid-pa-67f5ca","errorCode":null,"errorMessage":"template document tree plan contains an invalid parent operation","messagePattern":"template document tree plan contains an invalid parent operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":550,"sourceCode":"\t\t\"foldHeading\":   \"unfoldHeading\",\n\t\t\"unfoldHeading\": \"foldHeading\",\n\t\t\"setAttrs\":      \"setAttrs\",\n\t}\n\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 {","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L532-L568","documentation":"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.","triggerScenarios":"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.","commonSituations":"API/plugin code constructing transactions manually and forgetting IDs; payload deserialization dropping fields; test fixtures with synthetic do operations.","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"],"exampleFix":"// before\ndo := &Operation{Action: \"insert\", Data: md}\n// after\ndo := &Operation{Action: \"insert\", Data: md, ID: util.TimeNSID()}","handlingStrategy":"validation","validationCode":"for _, op := range tx.DoOperations {\n    if op == nil || op.ID == \"\" {\n        return errors.New(\"do operation missing ID\")\n    }\n}","typeGuard":"func hasValidDoOps(ops []*Operation) bool {\n    for _, op := range ops {\n        if op == nil || op.ID == \"\" {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Generate IDs (e.g. util.TimeNSID) for every do operation","Validate the transaction before calling AttachTemplateDocTreePlans"],"tags":["go","transaction","validation"],"backgroundTag":"empty-required-field","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"}