{"record":{"id":"8dc657636dd5a0dd","repo":"siyuan-note/siyuan","slug":"new-item-template-field-s-option-s-not-found","errorCode":null,"errorMessage":"new item template field [%s] option [%s] not found","messagePattern":"new item template field \\[(.+?)\\] option \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":339,"sourceCode":"\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 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfieldValue.Value, err = normalizeNewItemTemplateValue(fieldValue.Value, key)\n\t\t\tif nil != err {\n\t\t\t\treturn fmt.Errorf(\"new item template field [%s] value is invalid: %w\", keyID, err)\n\t\t\t}\n\t\t\tif KeyTypeSelect == key.Type || KeyTypeMSelect == key.Type {\n\t\t\t\tfor _, selection := range fieldValue.Value.MSelect {\n\t\t\t\t\tif nil != selection && nil == key.GetOption(selection.Content) {\n\t\t\t\t\t\treturn fmt.Errorf(\"new item template field [%s] option [%s] not found\", keyID, selection.Content)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid new item template field value mode [%s]\", fieldValue.Mode)\n\t\t}\n\t\tfieldValues[keyID] = fieldValue\n\t}\n\tif 0 == len(fieldValues) {\n\t\titemTemplate.FieldValues = nil\n\t} else {\n\t\titemTemplate.FieldValues = fieldValues\n\t}\n\treturn nil\n}\n\nfunc normalizeNewItemTemplateValue(value *Value, key *Key) (*Value, error) {\n\tvalue = value.Clone()","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L321-L357","documentation":"For select/multi-select keys, after normalizing a static value each selected option content is checked against the key's configured options via key.GetOption. If a selection's content does not match any defined option, the configuration is rejected because template-generated rows may only reference existing options.","triggerScenarios":"Calling SetNewItemTemplates with a static FieldValues entry on a KeyTypeSelect/KeyTypeMSelect key whose Value.MSelect contains a selection whose Content is not one of the key's declared options.","commonSituations":"An option was renamed or deleted after the template stored it; hardcoding option text that differs in case or whitespace from the defined option; copying select values between databases with different option sets.","solutions":["Update the selection Content to exactly match an existing option defined on the key","Add the missing option to the key before saving the template, or remove the stale selection","Re-derive selectable values from key.GetOptions() instead of hardcoding strings"],"exampleFix":"// before\nfv.Value = &av.Value{MSelect: []*av.ValueSelect{{Content: \"High \"}}} // option renamed\nerr := av.SetNewItemTemplates(config) // option [High ] not found\n// after\nfv.Value = &av.Value{MSelect: []*av.ValueSelect{{Content: \"High\"}}} // matches key option\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"for _, sel := range fv.Value.MSelect {\n\tif sel != nil && key.GetOption(sel.Content) == nil {\n\t\treturn fmt.Errorf(\"option %q not defined on key %s\", sel.Content, keyID)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Source selectable values from key.GetOptions() rather than hardcoding strings","Re-validate template selections after renaming or deleting key options"],"tags":["attribute-view","validation","options"],"backgroundTag":"resource-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"}