{"record":{"id":"46fecd83065fa6e5","repo":"siyuan-note/siyuan","slug":"new-item-template-field-s-not-found","errorCode":null,"errorMessage":"new item template field [%s] not found","messagePattern":"new item template field \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":311,"sourceCode":"\t\tif ret[i].TemplateID != ret[j].TemplateID {\n\t\t\treturn ret[i].TemplateID < ret[j].TemplateID\n\t\t}\n\t\treturn ret[i].KeyID < ret[j].KeyID\n\t})\n\treturn\n}\n\nfunc (av *AttributeView) normalizeNewItemTemplateFieldValues(itemTemplate *NewItemTemplate) error {\n\tif 0 == len(itemTemplate.FieldValues) {\n\t\titemTemplate.FieldValues = nil\n\t\treturn nil\n\t}\n\n\tfieldValues := map[string]*NewItemFieldValue{}\n\tfor keyID, fieldValue := range itemTemplate.FieldValues {\n\t\tkey, err := av.GetKey(keyID)\n\t\tif nil != err || nil == key {\n\t\t\treturn fmt.Errorf(\"new item template field [%s] not found\", keyID)\n\t\t}\n\t\tif !isNewItemTemplateEditableKeyType(key.Type) {\n\t\t\treturn fmt.Errorf(\"new item template field [%s] type [%s] is not editable\", keyID, key.Type)\n\t\t}\n\t\tif nil == fieldValue {\n\t\t\tcontinue\n\t\t}\n\t\tif \"\" == fieldValue.Mode {\n\t\t\tfieldValue.Mode = NewItemFieldValueStatic\n\t\t}\n\t\tswitch fieldValue.Mode {\n\t\tcase NewItemFieldValueCurrentTime:\n\t\t\tif KeyTypeDate != key.Type {\n\t\t\t\treturn fmt.Errorf(\"new item template field [%s] current time mode requires date type\", keyID)\n\t\t\t}\n\t\t\tfieldValue.Value = nil\n\t\tcase NewItemFieldValueStatic:\n\t\t\tif nil == fieldValue.Value {","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L293-L329","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the key ID exists via av.GetKey(keyID) before adding it to FieldValues and remove stale entries","Re-fetch the attribute view's key list and rebuild FieldValues from current key IDs","If the field was intentionally deleted, delete the matching FieldValues entry from every template"],"exampleFix":"// before\ntemplate.FieldValues[\"20240101-old-key00\"] = &av.NewItemFieldValue{...} // key removed\nerr := av.SetNewItemTemplates(config)\n// after\nif _, err := av.GetKey(\"20240101-old-key00\"); err == nil {\n\ttemplate.FieldValues[\"20240101-old-key00\"] = &av.NewItemFieldValue{...}\n}\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"for keyID := range template.FieldValues {\n\tif _, err := av.GetKey(keyID); err != nil {\n\t\tdelete(template.FieldValues, keyID)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-fetch key IDs from the current attribute view instead of caching them across edits","Prune FieldValues entries whenever a database field is removed"],"tags":["attribute-view","validation","referential-integrity"],"backgroundTag":"entity-not-found","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"}