{"record":{"id":"8cdcabec341fa6a8","repo":"siyuan-note/siyuan","slug":"cannot-add-an-attribute-view-block-key","errorCode":null,"errorMessage":"cannot add an attribute view block key","messagePattern":"cannot add an attribute view block key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":7473,"sourceCode":"\tif nil != err {\n\t\treturn\n\t}\n\n\tkey, err := newAttributeViewKey(keyID, keyName, keyType, keyIcon, dateFormat)\n\tif nil != err {\n\t\treturn err\n\t}\n\taddAttributeViewKey(attrView, currentView, key, previousKeyID)\n\n\terr = av.SaveAttributeView(attrView)\n\treturn\n}\n\nfunc newAttributeViewKey(keyID, keyName, keyType, keyIcon string, dateFormat av.DateDisplayFormat) (ret *av.Key, err error) {\n\tkeyTyp := av.KeyType(keyType)\n\tswitch keyTyp {\n\tcase av.KeyTypeBlock:\n\t\treturn nil, errors.New(\"cannot add an attribute view block key\")\n\tcase av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail,\n\t\tav.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox,\n\t\tav.KeyTypeRelation, av.KeyTypeRollup, av.KeyTypeLineNumber:\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported attribute view key type [%s]\", keyType)\n\t}\n\n\tret = av.NewKey(keyID, keyName, filterAttrViewIconValue(keyIcon), keyTyp)\n\tif av.KeyTypeDate == keyTyp || av.KeyTypeCreated == keyTyp || av.KeyTypeUpdated == keyTyp {\n\t\tif !dateFormat.IsValid() {\n\t\t\treturn nil, errors.New(\"invalid date display format\")\n\t\t}\n\t\tret.DateFormat = dateFormat\n\t}\n\tif av.KeyTypeRollup == keyTyp {\n\t\tret.Rollup = &av.Rollup{Calc: &av.RollupCalc{Operator: av.CalcOperatorNone}}\n\t}\n\treturn","sourceCodeStart":7455,"sourceCodeEnd":7491,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L7455-L7491","documentation":"newAttributeViewKey validates the requested key type before creating a column. The Block type is reserved for the built-in block column and cannot be user-added, so requesting it is rejected explicitly.","triggerScenarios":"Calling the add-attribute-view-key API (attr view add field transaction) with type \"block\".","commonSituations":"Plugins enumerating key types without filtering out \"block\"; scripts cloning an existing view's fields including the block key; UI not disabling the Block option.","solutions":["Do not add a block key; it already exists in every attribute view","Choose a real type such as \"text\", \"number\", \"select\", \"date\", \"relation\", etc.","Filter av.KeyTypeBlock out of any type list offered to users in a plugin"],"exampleFix":"// before\naddAttrViewKey(avID, keyID, name, \"block\", \"\", \"\")\n// after\naddAttrViewKey(avID, keyID, name, \"text\", \"\", \"\")","handlingStrategy":"validation","validationCode":"if (keyType === \"block\") throw new Error(\"block key already exists in every attribute view; pick another type\");","typeGuard":"const isAddableKeyType = (t: string): boolean =>\n  [\"text\",\"number\",\"date\",\"select\",\"mSelect\",\"url\",\"email\",\"phone\",\"mAsset\",\"template\",\"created\",\"updated\",\"checkbox\",\"relation\",\"rollup\",\"lineNumber\"].includes(t);","tryCatchPattern":"try { await addAttrViewKey(...); } catch (e) { if (String(e).includes(\"cannot add an attribute view block key\")) { /* fall back to text or skip */ } else throw e; }","preventionTips":["Filter \"block\" out of user-facing type pickers","Treat the block key as implicit in every view","Consult the petal typings for the addable key list"],"tags":["attribute-view","unsupported-type","api"],"backgroundTag":"unsupported-enum-value","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"}