{"record":{"id":"b791035d0c5cb5c9","repo":"siyuan-note/siyuan","slug":"date-display-format-is-only-available-for-date-fie","errorCode":null,"errorMessage":"date display format is only available for date fields","messagePattern":"date display format is only available for date fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":7670,"sourceCode":"\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc setAttributeViewColDateFormat(operation *Operation) (err error) {\n\tformat := av.DateDisplayFormat(operation.Format)\n\tif !format.IsValid() {\n\t\treturn errors.New(\"invalid date display format\")\n\t}\n\n\tattrView, err := av.ParseAttributeView(operation.AvID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tcolType := av.KeyType(operation.Typ)\n\tif av.KeyTypeDate != colType && av.KeyTypeCreated != colType && av.KeyTypeUpdated != colType {\n\t\treturn errors.New(\"date display format is only available for date fields\")\n\t}\n\tfor _, keyValues := range attrView.KeyValues {\n\t\tif keyValues.Key.ID == operation.ID && keyValues.Key.Type == colType {\n\t\t\tkeyValues.Key.DateFormat = format\n\t\t\tbreak\n\t\t}\n\t}\n\n\terr = av.SaveAttributeView(attrView)\n\treturn\n}\n\nfunc (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) {\n\terr := updateAttributeViewColumn(operation)\n\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn","sourceCodeStart":7652,"sourceCodeEnd":7688,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L7652-L7688","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the key's type (av.KeyType) is 'date', 'created', or 'updated' before sending the format update","Fix operation.Typ to match the actual column type, or target the correct column ID","Move the format setting into the UI flow that only shows for date columns","If the column should be a date, first create/use a date-type key instead"],"exampleFix":"// before\nop.Typ = \"text\"; op.Format = \"2006-01-02\"\n// after\nop.Typ = \"date\"; op.Format = string(av.DateFormatUserName) // only for date/created/updated keys","handlingStrategy":"validation","validationCode":"const DATE_TYPES = new Set([\"date\", \"created\", \"updated\"]);\nif (!DATE_TYPES.has(op.Typ)) throw new Error(\"date format applies only to date/created/updated keys\");","typeGuard":"const isDateTypeKey = (k) => [\"date\", \"created\", \"updated\"].includes(k.type);","tryCatchPattern":"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; } }","preventionTips":["Only render the format picker for date/created/updated columns","Verify the key type via the attribute view fetch before updating format","Re-check types after any column type change in the same session"],"tags":["attribute-view","validation","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}