{"record":{"id":"a6d09254a6faabc9","repo":"siyuan-note/siyuan","slug":"database-s-template-field-s-rendering-failed","errorCode":null,"errorMessage":"database [%s] template field [%s] rendering failed: %s","messagePattern":"database \\[(.+?)\\] template field \\[(.+?)\\] rendering failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/sql/av.go","lineNumber":861,"sourceCode":"\t\t\t\tif nil != compileErr {\n\t\t\t\t\tcompileErrCache[value.Template.Content] = compileErr\n\t\t\t\t\trenderErr = compileErr\n\t\t\t\t} else {\n\t\t\t\t\ttpl = compiled\n\t\t\t\t}\n\t\t\t} else if nil == tpl {\n\t\t\t\trenderErr = compileErrCache[value.Template.Content] // 复用首次解析的错误\n\t\t\t}\n\t\t\tif nil == renderErr {\n\t\t\t\tcontent, renderErr = executeTemplateField(tpl, ial, keyValues)\n\t\t\t}\n\t\t\tif nil != renderErr {\n\t\t\t\tkey, _ := attrView.GetKey(value.KeyID)\n\t\t\t\tkeyName := \"\"\n\t\t\t\tif nil != key {\n\t\t\t\t\tkeyName = key.Name\n\t\t\t\t}\n\t\t\t\terr = fmt.Errorf(\"database [%s] template field [%s] rendering failed: %s\", getAttrViewName(attrView), keyName, renderErr)\n\t\t\t}\n\n\t\t\tvalue.Template.Content = content\n\t\t\titems[item.GetID()] = append(keyValues, &av.KeyValues{Key: templateKey, Values: []*av.Value{value}})\n\t\t}\n\t}\n\treturn\n}\n\nfunc fillAttributeViewKeyValues(attrView *av.AttributeView, collection av.Collection) {\n\tfieldValues := map[string][]*av.Value{}\n\tfor _, item := range collection.GetItems() {\n\t\tfor _, val := range item.GetValues() {\n\t\t\tkeyID := val.KeyID\n\t\t\tfieldValues[keyID] = append(fieldValues[keyID], val)\n\t\t}\n\t}\n\tfor keyID, values := range fieldValues {","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/sql/av.go#L843-L879","documentation":"Database (attribute view) template columns are rendered as Go text/template with custom delimiters .action{ } and a function set from filesys.BuiltInTemplateFuncs plus SQL template funcs (compileTemplateField, av.go:182). When a column's content fails to parse or execute, the row records 'database [<av name>] template field [<column name>] rendering failed: <cause>'; the parse error is also logged at warn level. Rendering continues for other rows and the last error is returned.","triggerScenarios":"Template content with syntax errors - unbalanced .action{, stray }, unknown function (.action{SomeFunc}); calling a template function with wrong arity or wrong argument type; referencing fields that do not exist on the row context at execution time; using {{ }} instead of the .action{ } delimiters.","commonSituations":"Pasting doc-template snippets into a database template column (same syntax family, different available context); renaming a column that another template references; incomplete autocomplete of function names; templates written for a different SiYuan version's function set.","solutions":["Open the database named in the error, edit the template column named in the error, and fix the syntax - the <cause> suffix carries the exact template error (e.g. function 'X' not defined)","Use .action{ } delimiters, not {{ }} - this column type shares the doc template action syntax","Stick to context that exists on rows: IAL keys such as id, created, updated plus other column values","If a referenced column was renamed or deleted, update the template - stale references surface as execution errors"],"exampleFix":"before (template column content):\n.action{.updated\n\nafter:\n.action{.updated}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"Callers of attribute-view rendering (e.g. /api/av endpoints or plugin APIs that render databases) should check the returned error, log it, and degrade gracefully - render remaining columns and show the template column's raw text instead of failing the whole view.","preventionTips":["Test new template column content on a scratch row before applying to a large database","Use .action{ } delimiters - never {{ }} - in database template columns","Only reference context that exists on rows (id, created, updated, other columns); update templates after renaming referenced columns","Check the kernel log: the underlying parse error is logged at warn level with the template content"],"tags":["database","attribute-view","template","go-template","siyuan"],"backgroundTag":"template-render-failed","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}