{"record":{"id":"7c03f1b80e0adccf","repo":"siyuan-note/siyuan","slug":"database-blocks-are-not-supported-by-createdoctree","errorCode":null,"errorMessage":"database blocks are not supported by createDocTree templates","messagePattern":"database blocks are not supported by createDocTree templates","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":930,"sourceCode":"\t}\n\tif 0 < len(collector.nodes) && maxTemplateDocTreeOutputSize < buf.Len() {\n\t\terr = fmt.Errorf(\"template output exceeds %d bytes\", maxTemplateDocTreeOutputSize)\n\t\treturn\n\t}\n\tcollector.totalOutput = buf.Len()\n\tmd = buf.Bytes()\n\ttree, err = parseTemplateKTree(md)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"parse template [%s] failed: %s\", p, err)\n\t\treturn\n\t}\n\ttree.Box = sourceTree.Box\n\tif 0 < len(collector.nodes) {\n\t\tif err = collector.validateLocations(); nil != err {\n\t\t\treturn\n\t\t}\n\t\tif templateTreeContainsAttributeView(tree) {\n\t\t\terr = errors.New(\"database blocks are not supported by createDocTree templates\")\n\t\t\treturn\n\t\t}\n\t\tif err = renderTemplateDocTreeNodes(collector, tpl, tplFuncMap); nil != err {\n\t\t\treturn\n\t\t}\n\t}\n\tattributeViewPlans, attributeViewCopies, prepareErr := prepareTemplateAttributeViews(tree, preview)\n\tif nil != prepareErr {\n\t\terr = prepareErr\n\t\treturn\n\t}\n\n\tvar nodesNeedAppendChild, unlinks []*ast.Node\n\t// 模板内部块旧 ID 到新 ID 的映射，用于成套改写模板内部的自引用\n\tblockIDs := map[string]string{}\n\trestoreTabsSelection := captureTemplateTabsSelection(tree.Root)\n\tast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {\n\t\tif !entering {","sourceCodeStart":912,"sourceCodeEnd":948,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L912-L948","documentation":"Templates that call createDocTree generate new documents, and database (attribute view) blocks in such templates are not supported: the kernel rejects the combination explicitly because embedding/copying a database into generated doc trees is undefined in this path.","triggerScenarios":"renderTemplateSource with a template that both uses the createDocTree function (collector has nodes) and whose parsed tree contains an attribute view node (templateTreeContainsAttributeView returns true) — i.e. the template body includes a database block alongside createDocTree calls.","commonSituations":"A user adds a database embed to a template that also creates a doc tree; a copy-pasted template mixes doc-tree generation with an existing database block; a template evolved over time to include both features.","solutions":["Remove the database (attribute view) block from the createDocTree template.","Split into two templates: one that creates the doc tree and one rendered separately that contains the database block.","Render the database block through a normal document (non-createDocTree) template path."],"exampleFix":"// before (template body)\n{{ createDocTree . \"root\" }}\n<div data-type=\"NodeAttributeView\" data-av-id=\"20240501...\"></div>\n// after: move the av block out of the createDocTree template\n{{ createDocTree . \"root\" }}","handlingStrategy":"validation","validationCode":"// pre-check: does the template combine createDocTree with an av block?\nif strings.Contains(src, \"createDocTree\") && strings.Contains(src, \"data-av-id\") {\n    return errors.New(\"remove the database block from createDocTree templates\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never embed database blocks in templates that call createDocTree","Keep doc-tree generation templates free of av embeds"],"tags":["go","template","attribute-view","unsupported"],"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"}