{"record":{"id":"b3e58ecd6286dac0","repo":"siyuan-note/siyuan","slug":"new-item-template-field-s-not-found-b3e58e","errorCode":null,"errorMessage":"new item template field [%s] not found","messagePattern":"new item template field \\[(.+?)\\] not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":586,"sourceCode":"\t\tparent = \"/\" + parent\n\t}\n\treturn parent\n}\n\nfunc newItemTitleFromPath(renderedPath string) string {\n\tif \"\" == renderedPath || strings.HasSuffix(renderedPath, \"/\") {\n\t\treturn \"\"\n\t}\n\treturn normalizeDocTitle(path.Base(renderedPath))\n}\n\nfunc resolveNewItemFieldValues(attrView *av.AttributeView, itemTemplate *av.NewItemTemplate, createdAt time.Time,\n\tcarrierBoxID string) (ret map[string]*av.Value, err error) {\n\tret = map[string]*av.Value{}\n\tfor keyID, fieldValue := range itemTemplate.FieldValues {\n\t\tkey, getErr := attrView.GetKey(keyID)\n\t\tif nil != getErr || nil == key {\n\t\t\treturn nil, fmt.Errorf(\"new item template field [%s] not found\", keyID)\n\t\t}\n\t\tvar value *av.Value\n\t\tswitch fieldValue.Mode {\n\t\tcase av.NewItemFieldValueCurrentTime:\n\t\t\tif av.KeyTypeDate != key.Type {\n\t\t\t\treturn nil, fmt.Errorf(\"new item template field [%s] current time value is invalid\", keyID)\n\t\t\t}\n\t\t\tisNotTime := true\n\t\t\tif nil != key.Date {\n\t\t\t\tisNotTime = !key.Date.FillSpecificTime\n\t\t\t}\n\t\t\tvalue = &av.Value{Type: av.KeyTypeDate, Date: av.NewFormattedValueDate(createdAt.UnixMilli(), 0, av.DateFormatNone, isNotTime, false)}\n\t\tcase av.NewItemFieldValueStatic:\n\t\t\tif nil == fieldValue.Value || fieldValue.Value.Type != key.Type {\n\t\t\t\treturn nil, fmt.Errorf(\"new item template field [%s] value is invalid\", keyID)\n\t\t\t}\n\t\t\tvalue = fieldValue.Value.Clone()\n\t\t\tif av.KeyTypeRelation == key.Type {","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L568-L604","documentation":"resolveNewItemFieldValues materializes each template FieldValues entry into a concrete av.Value. Before evaluating a field's mode it looks the field up by key ID via attrView.GetKey; if the key is missing (or lookup errors), the template references a field that no longer exists in the database and creation aborts with this error. This is a template-vs-schema consistency check.","triggerScenarios":"createAttributeViewItem with a template whose FieldValues map contains a keyID that was deleted from the attribute view (column removed), or a key ID from a different database pasted into the template config.","commonSituations":"Deleting an attribute-view column without cleaning templates that fill it; copying template JSON between databases with different key IDs; sync merging where the column was removed on another device.","solutions":["Edit the new-item template and remove the entry for the missing field key from its FieldValues","Re-add a column with a matching key, or recreate the template so all referenced keys exist","After sync-related drift, reload the database so the .av reflects the current schema, then re-check the template"],"exampleFix":"// before\ntemplate.FieldValues[\"20240101120000-deletedkey\"] = &av.NewItemFieldValue{...}\n// after: reference only existing keys\nif _, err := attrView.GetKey(keyID); err == nil {\n    template.FieldValues[keyID] = &av.NewItemFieldValue{...}\n}","handlingStrategy":"validation","validationCode":"for keyID := range tpl.FieldValues {\n    if _, err := attrView.GetKey(keyID); err != nil {\n        return fmt.Errorf(\"template references missing field %s\", keyID)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prune template FieldValues whenever a column is deleted","Never copy template key IDs across databases","After sync, reload the database before using stored templates"],"tags":["attribute-view","template-schema-mismatch","go-kernel"],"backgroundTag":"record-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"}