{"record":{"id":"27a34ab70a6c2c5b","repo":"siyuan-note/siyuan","slug":"numberformat-requires-a-number-field-and-a-supported-format","errorCode":null,"errorMessage":"numberFormat requires a number field and a supported format","messagePattern":"numberFormat requires a number field and a supported format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_key_config.go","lineNumber":68,"sourceCode":"\t\t\tcase \"name\":\n\t\t\t\tif \"\" == strings.TrimSpace(text) {\n\t\t\t\t\treturn errors.New(\"field name must not be empty\")\n\t\t\t\t}\n\t\t\t\top.Name = text\n\t\t\t\treturn updateAttributeViewColumn(op)\n\t\t\tcase \"type\":\n\t\t\t\tif _, err = newAttributeViewKey(keyID, key.Name, text, key.Icon, key.DateFormat); nil != err {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\top.Typ = text\n\t\t\t\treturn updateAttributeViewColumn(op)\n\t\t\tcase \"icon\":\n\t\t\t\treturn setAttributeViewColIcon(op)\n\t\t\tcase \"desc\":\n\t\t\t\treturn setAttributeViewColDesc(op)\n\t\t\tcase \"numberFormat\":\n\t\t\t\tif av.KeyTypeNumber != key.Type || !slices.Contains(AttributeViewKeyNumberFormats, text) {\n\t\t\t\t\treturn errors.New(\"numberFormat requires a number field and a supported format\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColNumberFormat(op)\n\t\t\tcase \"dateFormat\":\n\t\t\t\treturn setAttributeViewColDateFormat(op)\n\t\t\tcase \"template\":\n\t\t\t\tif av.KeyTypeTemplate != key.Type {\n\t\t\t\t\treturn errors.New(\"template requires a template field; use renderTemplate for other fields\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColTemplate(op)\n\t\t\tcase \"renderTemplate\":\n\t\t\t\tif av.KeyTypeTemplate == key.Type {\n\t\t\t\t\treturn errors.New(\"use template for a template field\")\n\t\t\t\t}\n\t\t\t\treturn updateAttributeViewColTemplate(op)\n\t\t\t}\n\t\tcase \"autoFillNow\", \"fillSpecificTime\", \"includeTime\":\n\t\t\tflag, ok := value.(bool)\n\t\t\tif !ok {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_key_config.go#L50-L86","documentation":"The \"numberFormat\" setting only applies to fields whose type is KeyTypeNumber, and the value must be one of the supported formats listed in AttributeViewKeyNumberFormats. Applying it to a non-number field, or using an unsupported format string, is rejected.","triggerScenarios":"Calling UpdateAttributeViewKeyConfig with {\"numberFormat\": \"2\"} on a text/date/template field, or with a typo'd/unknown format such as {\"numberFormat\": \"percent\"}.","commonSituations":"Scripts applying number formatting to columns of unknown type; format names guessed instead of taken from the supported list; a field whose type was changed after the format was chosen.","solutions":["Change the field type to \"number\" first, then apply numberFormat in a second call","Use a format string from AttributeViewKeyNumberFormats exactly (e.g. \"2\", \"10000.00\")","Check key.Type == number before sending numberFormat from client code"],"exampleFix":"// before\nupdateKeyConfig(avID, textKeyID, {\"numberFormat\": \"2\"})\n// after\nupdateKeyConfig(avID, numberKeyID, {\"numberFormat\": \"2\"})","handlingStrategy":"validation","validationCode":"const NUMBER_FORMATS = ['','2','10000','10000.0','10000.00','0.1%','0.10%','0.12%','10000.00W','1.00E+03','2000-01-01','2000-01'];\nfunction assertNumberFormat(key, fmt) { if (key.type !== 'number') throw new Error('numberFormat requires a number field'); if (!NUMBER_FORMATS.includes(fmt)) throw new Error('unsupported format'); }","typeGuard":"const isNumberField = (key) => key?.type === 'number';","tryCatchPattern":"try { await updateKeyConfig(avID, keyID, { numberFormat: fmt }); } catch (e) { if (/numberFormat requires/.test(e.message)) { await updateKeyConfig(avID, keyID, { type: 'number' }); return updateKeyConfig(avID, keyID, { numberFormat: fmt }); } throw e; }","preventionTips":["Check the column type is number before applying numberFormat","Take format strings from the kernel's supported-format list, not guesses","Re-read the field type after any type change before further config calls"],"tags":["api","validation","attribute-view","field-type"],"backgroundTag":"unsupported-operation","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"}