siyuan-note/siyuan · error

invalid attribute view field template

Error message

invalid attribute view field template

What it means

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.

Solutions

  1. Send operation.Data as a plain string containing the template expression
  2. Ensure Data is present (use an empty string to clear, not null)
  3. Fix serialization in the caller so it does not wrap or stringify the expression

Example fix

// before
{avID, id, typ: "template", data: {template: "=NOW()"}}
// after
{avID, id, typ: "template", data: "=NOW()"}
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof templateContent !== "string") throw new Error("template must be a plain string expression");

Type guard

const isTemplate = (v: unknown): v is string => typeof v === "string";

Try / catch

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; }

Prevention

When it happens

Trigger: 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": "..."}.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/908396abe905e6c0. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view.go:7582

}

func (tx *Transaction) doUpdateAttrViewColTemplate(operation *Operation) (ret *TxErr) {
	err := updateAttributeViewColTemplate(operation)
	if err != nil {
		return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
	}
	return
}

func updateAttributeViewColTemplate(operation *Operation) (err error) {
	attrView, err := av.ParseAttributeView(operation.AvID)
	if err != nil {
		return
	}

	templateContent, ok := operation.Data.(string)
	if !ok {
		return errors.New("invalid attribute view field template")
	}
	colType := av.KeyType(operation.Typ)
	for _, keyValues := range attrView.KeyValues {
		if keyValues.Key.ID != operation.ID || keyValues.Key.Type != colType {
			continue
		}
		if av.KeyTypeTemplate == colType {
			keyValues.Key.Template = templateContent
		} else {
			keyValues.Key.RenderTemplate = templateContent
		}
		break
	}

	regenAttrViewGroups(attrView)
	err = av.SaveAttributeView(attrView)
	return
}

View on GitHub (pinned to 9f775e8a12)