{"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":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/sql/av.go","lineNumber":767,"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":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/sql/av.go#L749-L785","documentation":"Wraps a failure during Attribute View (database) template-field rendering: either compileTemplateField failed to parse the template, or executeTemplateField failed while rendering it against the block's ial and keyValues. The wrapper names the database, the template key (field name), and the underlying render error. Rendering is cached — a bad template keeps failing with the cached compile error.","triggerScenarios":"An Attribute View contains a template column whose content has invalid template syntax or references missing/unavailable keys/values; rendering runs during av value calculation/fill. Triggered when opening/computing a database view with such a template field.","commonSituations":"User edits a template field with a syntax error (unbalanced delimiter, unknown helper); template references a key that was deleted from the AV; migration/import produced a malformed template.","solutions":["Open the Attribute View and fix the template field named in the error — correct the syntax per the template grammar used by compileTemplateField.","Ensure any referenced keys exist in the AV (the error's keyName indicates the offending field).","If the template is unrecoverable, clear and re-enter it to reset the cached compile error."],"exampleFix":"// before (template field content)\n{{ .blocks[0].content \n// after\n{{ .blocks[0].content }}","handlingStrategy":"try-catch","validationCode":"// Validate template syntax before saving the AV field (plugin/UI side).\nfunction validateTemplate(src: string): void {\n  let depth = 0\n  for (const ch of src) {\n    if (ch === '{') depth++\n    if (ch === '}') depth--\n    if (depth < 0) throw new Error('unbalanced } in template')\n  }\n  if (depth !== 0) throw new Error('unbalanced { in template')\n}","typeGuard":null,"tryCatchPattern":"// Wrap AV load to surface template errors clearly.\ntry { await loadAttributeView(avID) }\ncatch (e) {\n  if (/template field .* rendering failed/i.test(String(e))) {\n    console.warn('fix the named template field in the database:', e.message)\n  } else throw e\n}","preventionTips":["Validate template syntax in the editor before saving the AV field.","Avoid referencing deleted keys in templates.","If a template becomes unrecoverable, clear and re-enter it to reset the cached compile error."],"tags":["attribute-view","database","template","rendering"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}