siyuan-note/siyuan · error
database [%s] template field [%s] rendering failed: %s
Error message
database [%s] template field [%s] rendering failed: %s
What it means
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.
Source
Thrown at kernel/sql/av.go:767
if nil != compileErr {
compileErrCache[value.Template.Content] = compileErr
renderErr = compileErr
} else {
tpl = compiled
}
} else if nil == tpl {
renderErr = compileErrCache[value.Template.Content] // 复用首次解析的错误
}
if nil == renderErr {
content, renderErr = executeTemplateField(tpl, ial, keyValues)
}
if nil != renderErr {
key, _ := attrView.GetKey(value.KeyID)
keyName := ""
if nil != key {
keyName = key.Name
}
err = fmt.Errorf("database [%s] template field [%s] rendering failed: %s", getAttrViewName(attrView), keyName, renderErr)
}
value.Template.Content = content
items[item.GetID()] = append(keyValues, &av.KeyValues{Key: templateKey, Values: []*av.Value{value}})
}
}
return
}
func fillAttributeViewKeyValues(attrView *av.AttributeView, collection av.Collection) {
fieldValues := map[string][]*av.Value{}
for _, item := range collection.GetItems() {
for _, val := range item.GetValues() {
keyID := val.KeyID
fieldValues[keyID] = append(fieldValues[keyID], val)
}
}
for keyID, values := range fieldValues {View on GitHub (pinned to 251596fc0d)
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.
Example fix
// before (template field content)
{{ .blocks[0].content
// after
{{ .blocks[0].content }} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate template syntax before saving the AV field (plugin/UI side).
function validateTemplate(src: string): void {
let depth = 0
for (const ch of src) {
if (ch === '{') depth++
if (ch === '}') depth--
if (depth < 0) throw new Error('unbalanced } in template')
}
if (depth !== 0) throw new Error('unbalanced { in template')
} Try / catch
// Wrap AV load to surface template errors clearly.
try { await loadAttributeView(avID) }
catch (e) {
if (/template field .* rendering failed/i.test(String(e))) {
console.warn('fix the named template field in the database:', e.message)
} else throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- --av is required
- database not found: %s
- --av, --name and --type are required
- --av and --key are required
- --block is required for non-detached rows
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/a6d09254a6faabc9.
Report an issue: GitHub.