{"record":{"id":"1f13b3972fc4bb1c","repo":"siyuan-note/siyuan","slug":"new-item-template-field-s-value-is-invalid","errorCode":null,"errorMessage":"new item template field [%s] value is invalid","messagePattern":"new item template field \\[(.+?)\\] value is invalid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":601,"sourceCode":"\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 {\n\t\t\t\tfilterNewItemTemplateRelationValue(attrView, key, value, carrierBoxID)\n\t\t\t\tif nil == value.Relation || 0 == len(value.Relation.BlockIDs) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"new item template field [%s] value mode is invalid\", keyID)\n\t\t}\n\t\tret[keyID] = value\n\t}\n\treturn\n}\n\nfunc filterNewItemTemplateRelationValue(attrView *av.AttributeView, key *av.Key, value *av.Value,\n\tcarrierBoxID string) {","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L583-L619","documentation":"For mode NewItemFieldValueStatic, the template must supply a non-nil Value whose Type exactly matches the target key's type. If Value is nil or the types disagree, resolveNewItemFieldValues rejects the field with this error, because it cannot safely clone/store a value of the wrong type into the column.","triggerScenarios":"createAttributeViewItem with a template whose static FieldValues entry has Value: nil, or a value typed e.g. KeyTypeText for a KeyTypeNumber key (fieldValue.Value.Type != key.Type).","commonSituations":"Hand-written or plugin-generated template JSON missing the Value object; column type changed after the static value was authored; copying templates across databases with mismatched key types.","solutions":["Edit the template and provide a static value object whose Type matches the column type","If the column type changed, rewrite the static value with the new type (e.g. av.NewValueText) or switch the field to current-time mode","Remove the FieldValues entry if the field should be left empty"],"exampleFix":"// before\n&av.NewItemFieldValue{Mode: av.NewItemFieldValueStatic, Value: nil}\n// after\n&av.NewItemFieldValue{Mode: av.NewItemFieldValueStatic, Value: av.NewValueText(\"todo\")}","handlingStrategy":"validation","validationCode":"if fv.Mode == av.NewItemFieldValueStatic {\n    if fv.Value == nil || fv.Value.Type != key.Type {\n        return fmt.Errorf(\"static value missing or wrong type for %s\", keyID)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct static values with the typed constructors (av.NewValueText, etc.)","Re-author static values after any column type change","Validate template JSON before persisting it to the .av file"],"tags":["attribute-view","type-mismatch","go-kernel"],"backgroundTag":"invalid-argument-value","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"}