siyuan-note/siyuan · error

new item template field

Error message

new item template field [%s] not found

What it means

normalizeNewItemTemplateFieldValues resolves each key ID in a template's FieldValues through AttributeView.GetKey. If the key does not exist in the attribute view (GetKey returns an error or nil), the template configuration is invalid and SetNewItemTemplates fails. This guards against template field values pointing at fields that were deleted from the database.

Solutions

  1. Verify the key ID exists via av.GetKey(keyID) before adding it to FieldValues and remove stale entries
  2. Re-fetch the attribute view's key list and rebuild FieldValues from current key IDs
  3. If the field was intentionally deleted, delete the matching FieldValues entry from every template

Example fix

// before
template.FieldValues["20240101-old-key00"] = &av.NewItemFieldValue{...} // key removed
err := av.SetNewItemTemplates(config)
// after
if _, err := av.GetKey("20240101-old-key00"); err == nil {
	template.FieldValues["20240101-old-key00"] = &av.NewItemFieldValue{...}
}
err := av.SetNewItemTemplates(config)
Defensive patterns

Strategy: validation

Validate before calling

for keyID := range template.FieldValues {
	if _, err := av.GetKey(keyID); err != nil {
		delete(template.FieldValues, keyID)
	}
}

Prevention

When it happens

Trigger: Calling SetNewItemTemplates with FieldValues containing a keyID that no longer exists in the attribute view (field deleted elsewhere, wrong key ID copied, or a key from a different attribute view).

Common situations: A database field was removed while a plugin still caches old key IDs; copying a template config between two different databases; hand-editing exported config JSON with a stale or mistyped key ID.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at kernel/av/new_item_template.go:311

		if ret[i].TemplateID != ret[j].TemplateID {
			return ret[i].TemplateID < ret[j].TemplateID
		}
		return ret[i].KeyID < ret[j].KeyID
	})
	return
}

func (av *AttributeView) normalizeNewItemTemplateFieldValues(itemTemplate *NewItemTemplate) error {
	if 0 == len(itemTemplate.FieldValues) {
		itemTemplate.FieldValues = nil
		return nil
	}

	fieldValues := map[string]*NewItemFieldValue{}
	for keyID, fieldValue := range itemTemplate.FieldValues {
		key, err := av.GetKey(keyID)
		if nil != err || nil == key {
			return fmt.Errorf("new item template field [%s] not found", keyID)
		}
		if !isNewItemTemplateEditableKeyType(key.Type) {
			return fmt.Errorf("new item template field [%s] type [%s] is not editable", keyID, key.Type)
		}
		if nil == fieldValue {
			continue
		}
		if "" == fieldValue.Mode {
			fieldValue.Mode = NewItemFieldValueStatic
		}
		switch fieldValue.Mode {
		case NewItemFieldValueCurrentTime:
			if KeyTypeDate != key.Type {
				return fmt.Errorf("new item template field [%s] current time mode requires date type", keyID)
			}
			fieldValue.Value = nil
		case NewItemFieldValueStatic:
			if nil == fieldValue.Value {

View on GitHub (pinned to 9f775e8a12)