{"record":{"id":"a8f8288c1432ab2f","repo":"siyuan-note/siyuan","slug":"date-value-is-missing","errorCode":null,"errorMessage":"date value is missing","messagePattern":"date value is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":371,"sourceCode":"\treturn nil\n}\n\nfunc normalizeNewItemTemplateValue(value *Value, key *Key) (*Value, error) {\n\tvalue = value.Clone()\n\tswitch key.Type {\n\tcase KeyTypeText:\n\t\tif nil == value.Text {\n\t\t\treturn nil, errors.New(\"text value is missing\")\n\t\t}\n\t\tvalue.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil\n\tcase KeyTypeNumber:\n\t\tif nil == value.Number {\n\t\t\treturn nil, errors.New(\"number value is missing\")\n\t\t}\n\t\tvalue.Text, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil\n\tcase KeyTypeDate:\n\t\tif nil == value.Date {\n\t\t\treturn nil, errors.New(\"date value is missing\")\n\t\t}\n\t\tvalue.Text, value.Number, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil\n\tcase KeyTypeSelect, KeyTypeMSelect:\n\t\tvar selections []*ValueSelect\n\t\tfor _, selection := range value.MSelect {\n\t\t\tif nil != selection && \"\" != strings.TrimSpace(selection.Content) {\n\t\t\t\tselections = append(selections, selection)\n\t\t\t}\n\t\t}\n\t\tif KeyTypeSelect == key.Type && 1 < len(selections) {\n\t\t\tselections = selections[:1]\n\t\t}\n\t\tvalue.MSelect = selections\n\t\tvalue.Text, value.Number, value.Date, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil\n\tcase KeyTypeURL:\n\t\tif nil == value.URL {\n\t\t\treturn nil, errors.New(\"URL value is missing\")\n\t\t}","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L353-L389","documentation":"normalizeNewItemTemplateValue validates a template row value against its attribute-view key type. When the key type is KeyTypeDate but the Value's Date field is nil, the value cannot serve as a date template value, so the function aborts with 'date value is missing'. The nil Date is a developer-side omission: the JSON payload supplied a value whose type is date but carried no date object.","triggerScenarios":"Calling PruneInvalidNewItemTemplateFieldValues or normalizeNewItemTemplateFieldValues with a value where Value.Type/Key.Type is KeyTypeDate and Value.Date == nil (e.g. JSON template value omitting the 'date' object or only setting Text).","commonSituations":"Hand-written or plugin-generated new-item templates where the value object was copied from a text field and the date sub-object was forgotten; API clients constructing Values via struct literals that zero-initialize the Date pointer.","solutions":["Add a non-nil Date object to the template value for the date-typed field","Change the field/key type to match the value actually provided (e.g. text)","Remove the value entry so it is pruned before normalization","Check for nil before calling and skip or default-fill the date"],"exampleFix":"// before\n{\"type\":\"date\"}                       // Date object omitted\n// after\n{\"type\":\"date\",\"date\":{\"content\":\"2026-01-01 00:00:00\"}}","handlingStrategy":"validation","validationCode":"if v.Type == av.KeyTypeDate && v.Date == nil {\n    return fmt.Errorf(\"date value requires a date object\")\n}","typeGuard":"func hasDate(v *av.Value) bool { return v != nil && v.Type == av.KeyTypeDate && v.Date != nil }","tryCatchPattern":null,"preventionTips":["Always populate the type-specific sub-object (Date) when setting Value.Type","Round-trip template JSON through the normalizer in tests before shipping","Never reuse a value struct across fields of different types without resetting fields"],"tags":["attribute-view","validation","nil-value"],"backgroundTag":"null-argument","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"}