siyuan-note/siyuan · error
date value is missing
Error message
date value is missing
What it means
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.
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
Example fix
// before
{"type":"date"} // Date object omitted
// after
{"type":"date","date":{"content":"2026-01-01 00:00:00"}} Defensive patterns
Strategy: validation
Validate before calling
if v.Type == av.KeyTypeDate && v.Date == nil {
return fmt.Errorf("date value requires a date object")
} Type guard
func hasDate(v *av.Value) bool { return v != nil && v.Type == av.KeyTypeDate && v.Date != nil } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- checkbox value is missing
- email value is missing
- phone value is missing
- URL value is missing
- at least one visible view is required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a8f8288c1432ab2f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/new_item_template.go:371
return nil
}
func normalizeNewItemTemplateValue(value *Value, key *Key) (*Value, error) {
value = value.Clone()
switch key.Type {
case KeyTypeText:
if nil == value.Text {
return nil, errors.New("text value is missing")
}
value.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
case KeyTypeNumber:
if nil == value.Number {
return nil, errors.New("number value is missing")
}
value.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
case KeyTypeDate:
if nil == value.Date {
return nil, errors.New("date value is missing")
}
value.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
case KeyTypeSelect, KeyTypeMSelect:
var selections []*ValueSelect
for _, selection := range value.MSelect {
if nil != selection && "" != strings.TrimSpace(selection.Content) {
selections = append(selections, selection)
}
}
if KeyTypeSelect == key.Type && 1 < len(selections) {
selections = selections[:1]
}
value.MSelect = selections
value.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
case KeyTypeURL:
if nil == value.URL {
return nil, errors.New("URL value is missing")
}View on GitHub (pinned to 9f775e8a12)