siyuan-note/siyuan · error

date display format is only available for date fields

Error message

date display format is only available for date fields

What it means

The date display format setting (setAttributeViewColDateFormat) only applies to columns whose type is date, created, or updated. When the target column has any other type (text, number, select, etc.), the kernel refuses to store a DateFormat on it. This guards the invariant that DateFormat is only meaningful on time-based keys.

Solutions

  1. Check the key's type (av.KeyType) is 'date', 'created', or 'updated' before sending the format update
  2. Fix operation.Typ to match the actual column type, or target the correct column ID
  3. Move the format setting into the UI flow that only shows for date columns
  4. If the column should be a date, first create/use a date-type key instead

Example fix

// before
op.Typ = "text"; op.Format = "2006-01-02"
// after
op.Typ = "date"; op.Format = string(av.DateFormatUserName) // only for date/created/updated keys
Defensive patterns

Strategy: validation

Validate before calling

const DATE_TYPES = new Set(["date", "created", "updated"]);
if (!DATE_TYPES.has(op.Typ)) throw new Error("date format applies only to date/created/updated keys");

Type guard

const isDateTypeKey = (k) => ["date", "created", "updated"].includes(k.type);

Try / catch

try { await setColDateFormat(op); } catch (e) { if (String(e).includes("only available for date fields")) { /* re-check key type or retarget the column */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling the set-date-format API with operation.Typ set to a non-date key type (e.g. 'text' or 'number') while supplying operation.Format; sending a date-format update to the wrong column ID.

Common situations: Plugin UI that doesn't disable the format picker for non-date columns; column type changed after the format request was built; mistaken column ID in the operation payload.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/b791035d0c5cb5c9. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view.go:7670

		return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
	}
	return
}

func setAttributeViewColDateFormat(operation *Operation) (err error) {
	format := av.DateDisplayFormat(operation.Format)
	if !format.IsValid() {
		return errors.New("invalid date display format")
	}

	attrView, err := av.ParseAttributeView(operation.AvID)
	if err != nil {
		return
	}

	colType := av.KeyType(operation.Typ)
	if av.KeyTypeDate != colType && av.KeyTypeCreated != colType && av.KeyTypeUpdated != colType {
		return errors.New("date display format is only available for date fields")
	}
	for _, keyValues := range attrView.KeyValues {
		if keyValues.Key.ID == operation.ID && keyValues.Key.Type == colType {
			keyValues.Key.DateFormat = format
			break
		}
	}

	err = av.SaveAttributeView(attrView)
	return
}

func (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) {
	err := updateAttributeViewColumn(operation)
	if err != nil {
		return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
	}
	return

View on GitHub (pinned to 9f775e8a12)