{"record":{"id":"908396abe905e6c0","repo":"siyuan-note/siyuan","slug":"invalid-attribute-view-field-template","errorCode":null,"errorMessage":"invalid attribute view field template","messagePattern":"invalid attribute view field template","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":7582,"sourceCode":"}\n\nfunc (tx *Transaction) doUpdateAttrViewColTemplate(operation *Operation) (ret *TxErr) {\n\terr := updateAttributeViewColTemplate(operation)\n\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc updateAttributeViewColTemplate(operation *Operation) (err error) {\n\tattrView, err := av.ParseAttributeView(operation.AvID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\ttemplateContent, ok := operation.Data.(string)\n\tif !ok {\n\t\treturn errors.New(\"invalid attribute view field template\")\n\t}\n\tcolType := av.KeyType(operation.Typ)\n\tfor _, keyValues := range attrView.KeyValues {\n\t\tif keyValues.Key.ID != operation.ID || keyValues.Key.Type != colType {\n\t\t\tcontinue\n\t\t}\n\t\tif av.KeyTypeTemplate == colType {\n\t\t\tkeyValues.Key.Template = templateContent\n\t\t} else {\n\t\t\tkeyValues.Key.RenderTemplate = templateContent\n\t\t}\n\t\tbreak\n\t}\n\n\tregenAttrViewGroups(attrView)\n\terr = av.SaveAttributeView(attrView)\n\treturn\n}","sourceCodeStart":7564,"sourceCodeEnd":7600,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L7564-L7600","documentation":"updateAttributeViewColTemplate reads the template expression from operation.Data and requires it to be a plain string. If Data is any other type (nil, object, number), the kernel rejects the update with this error before applying the template.","triggerScenarios":"Calling the set-attribute-view-template / update template transaction with Data not set to the template string, or wrapping it in an object like {\"template\": \"...\"}.","commonSituations":"Plugins passing a parsed config object instead of the raw formula string; nil Data when the template input was empty and dropped by UI marshaling.","solutions":["Send operation.Data as a plain string containing the template expression","Ensure Data is present (use an empty string to clear, not null)","Fix serialization in the caller so it does not wrap or stringify the expression"],"exampleFix":"// before\n{avID, id, typ: \"template\", data: {template: \"=NOW()\"}}\n// after\n{avID, id, typ: \"template\", data: \"=NOW()\"}","handlingStrategy":"type-guard","validationCode":"if (typeof templateContent !== \"string\") throw new Error(\"template must be a plain string expression\");","typeGuard":"const isTemplate = (v: unknown): v is string => typeof v === \"string\";","tryCatchPattern":"try { await setAttrViewTemplate(avID, keyID, tpl); } catch (e) { if (String(e).includes(\"invalid attribute view field template\")) { /* re-send Data as string */ } else throw e; }","preventionTips":["Send the raw expression string, not a wrapper object","Use \"\" to clear a template, never null","Validate payload shape before enqueueing the transaction"],"tags":["attribute-view","template","type-mismatch"],"backgroundTag":"invalid-argument-format","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"}