siyuan-note/siyuan · error

checkbox value is missing

Error message

checkbox value is missing

What it means

Thrown inside normalizeNewItemTemplateValue (kernel/av/new_item_template.go:414-415) when key.Type == KeyTypeCheckbox but value.Checkbox is nil. The function needs a *ValueCheckbox (which carries a Checked bool) to set as the template default. The strict caller wraps the error; the prune caller silently deletes the field.

Source

Thrown at kernel/av/new_item_template.go:415

		if nil == value.Phone {
			return nil, errors.New("phone value is missing")
		}
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.MAsset, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeMAsset:
		var assets []*ValueAsset
		for _, asset := range value.MAsset {
			if nil != asset && "" != strings.TrimSpace(asset.Content) {
				if AssetTypeFile != asset.Type && AssetTypeImage != asset.Type {
					return nil, fmt.Errorf("invalid asset type [%s]", asset.Type)
				}
				assets = append(assets, asset)
			}
		}
		value.MAsset = assets
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeCheckbox:
		if nil == value.Checkbox {
			return nil, errors.New("checkbox value is missing")
		}
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
	case KeyTypeRelation:
		if nil == value.Relation {
			return nil, errors.New("relation value is missing")
		}
		for _, blockID := range value.Relation.BlockIDs {
			if !ast.IsNodeIDPattern(blockID) {
				return nil, fmt.Errorf("invalid relation block ID [%s]", blockID)
			}
		}
		value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox = nil, nil, nil, nil, nil, nil, nil, nil, nil
	default:
		return nil, fmt.Errorf("unsupported value type [%s]", key.Type)
	}
	value.Block, value.Template, value.Created, value.Updated, value.Rollup = nil, nil, nil, nil, nil
	value.ID = ""
	value.KeyID = ""

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Include a non-null checkbox object, e.g. {"checkbox": {"checked": false}}
  2. Omit the field from FieldValues if no default checkbox state is needed
  3. Set Value.Checkbox = &ValueCheckbox{Checked: false} before persisting

Example fix

// before
fieldValue.Value = &av.Value{Type: av.KeyTypeCheckbox}
// after
fieldValue.Value = &av.Value{Type: av.KeyTypeCheckbox, Checkbox: &av.ValueCheckbox{Checked: false}}
Defensive patterns

Strategy: validation

Validate before calling

func validateCheckboxValue(value *av.Value, key *av.Key) error {
    if key.Type == av.KeyTypeCheckbox && value.Checkbox == nil {
        return fmt.Errorf("checkbox key requires a non-nil Value.Checkbox")
    }
    return nil
}

Type guard

func hasCheckboxValue(v *av.Value) bool {
    return v != nil && v.Checkbox != nil
}

Prevention

When it happens

Trigger: Saving an Attribute View new-item template with a static-mode checkbox field whose Value JSON does not include a non-null "checkbox" sub-field.

Common situations: Programmatic template creation that omits the checkbox payload expecting it to default to unchecked; reusing a generic Value struct; schema migration from a pre-checkbox version.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/ca5e1ba8757f7367. Report an issue: GitHub.