{"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":7133,"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":7115,"sourceCodeEnd":7151,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L7115-L7151","documentation":"Thrown by setAttributeViewColDateFormat when operation.Typ is not one of KeyTypeDate, KeyTypeCreated, or KeyTypeUpdated. Date display format is only meaningful for those three column types; applying it to text, number, select, etc. is rejected because it would have no effect and would mislead callers.","triggerScenarios":"Sending a setAttrViewColDateFormat operation against a non-date column — e.g. the UI dispatched the format change against the wrong column ID, or a column was retyped from date to text but a stale format operation still fired.","commonSituations":"Frontend state desync after a column type change; copy-paste of an operation with a stale typ; a script that applies the same format to every column indiscriminately.","solutions":["Only invoke setAttrViewColDateFormat when the target column's type is date, created, or updated; read the current type first.","After retyping a column, clear pending format-change operations on the client so they do not fire against the new type.","Guard the UI: hide the date-format control for non-date columns."],"exampleFix":"// before\nsetAttributeViewColDateFormat({ avID, id: colID, typ: 'text', format })\n// after\nconst col = getAttrViewKey(avID, colID)\nif (!['date','created','updated'].includes(col.type)) return\nsetAttributeViewColDateFormat({ avID, id: colID, typ: col.type, format })","handlingStrategy":"type-guard","validationCode":"const col = (await getAttrViewKeys(avID)).find(k => k.id === op.id)\nif (!col || !['date','created','updated'].includes(col.type)) { /* skip date-format op for non-date column */ }","typeGuard":"type DateLikeType = 'date' | 'created' | 'updated'\nfunction isDateLikeType(t: string): t is DateLikeType { return t === 'date' || t === 'created' || t === 'updated' }","tryCatchPattern":null,"preventionTips":["Only show the date-format control on date/created/updated columns.","Drop pending format operations after a column retype."],"tags":["attribute-view","date-format","update-column","type-mismatch"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}