{"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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L293-L329","documentation":"normalizeNewItemTemplateFieldValues iterates itemTemplate.FieldValues and looks up each keyID via av.GetKey; if the key is missing (deleted column) or GetKey errored, the field reference is rejected. A template's FieldValues must point at columns that still exist on the AV.","triggerScenarios":"A column is deleted while the new-item-template editor is open; the client submits stale FieldValues referencing the removed keyID; a sync applies a remote column deletion locally before the template save lands; an import payload from a different AV schema.","commonSituations":"Race between column removal and template save; client caches the schema and does not refresh; copy of a template between AVs whose column sets differ.","solutions":["Before saving, prune FieldValues entries whose keyID is no longer in av.KeyValues.","Refresh the AV schema client-side before opening the template editor.","When deleting a column server-side, also call RemoveNewItemTemplateFieldValue (new_item_template.go:113) in the same transaction."],"exampleFix":"// before\nFieldValues: map[string]*av.NewItemFieldValue{\"deleted-key\": {...}}\n// after\ndelete(FieldValues, \"deleted-key\")","handlingStrategy":"validation","validationCode":"for keyID := range t.FieldValues {\n    if _, err := av.GetKey(keyID); err != nil {\n        delete(t.FieldValues, keyID) // prune stale references before saving\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Refresh the AV schema client-side before editing templates.","On column deletion server-side, call RemoveNewItemTemplateFieldValue in the same transaction.","Drop FieldValues entries that no longer resolve before submit."],"tags":["av","new-item-template","field","stale-reference","validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}