siyuan-note/siyuan · error
cannot add an attribute view block key
Error message
cannot add an attribute view block key
What it means
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.
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
Example fix
// before addAttrViewKey(avID, keyID, name, "block", "", "") // after addAttrViewKey(avID, keyID, name, "text", "", "")
Defensive patterns
Strategy: validation
Validate before calling
if (keyType === "block") throw new Error("block key already exists in every attribute view; pick another type"); Type guard
const isAddableKeyType = (t: string): boolean => ["text","number","date","select","mSelect","url","email","phone","mAsset","template","created","updated","checkbox","relation","rollup","lineNumber"].includes(t);
Try / catch
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; } Prevention
- 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
When it happens
Trigger: Calling the add-attribute-view-key API (attr view add field transaction) with type "block".
Common situations: 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.
Related errors
- [/api/av/batchSetAttributeViewBlockAttrs] parameter [rowID]…
- attribute view item markdown is nil
- config must contain exactly one setting; use separate calls…
- Field [keyIDs] is required
- field name must not be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/8cdcabec341fa6a8.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/attribute_view.go:7473
if nil != err {
return
}
key, err := newAttributeViewKey(keyID, keyName, keyType, keyIcon, dateFormat)
if nil != err {
return err
}
addAttributeViewKey(attrView, currentView, key, previousKeyID)
err = av.SaveAttributeView(attrView)
return
}
func newAttributeViewKey(keyID, keyName, keyType, keyIcon string, dateFormat av.DateDisplayFormat) (ret *av.Key, err error) {
keyTyp := av.KeyType(keyType)
switch keyTyp {
case av.KeyTypeBlock:
return nil, errors.New("cannot add an attribute view block key")
case av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail,
av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox,
av.KeyTypeRelation, av.KeyTypeRollup, av.KeyTypeLineNumber:
default:
return nil, fmt.Errorf("unsupported attribute view key type [%s]", keyType)
}
ret = av.NewKey(keyID, keyName, filterAttrViewIconValue(keyIcon), keyTyp)
if av.KeyTypeDate == keyTyp || av.KeyTypeCreated == keyTyp || av.KeyTypeUpdated == keyTyp {
if !dateFormat.IsValid() {
return nil, errors.New("invalid date display format")
}
ret.DateFormat = dateFormat
}
if av.KeyTypeRollup == keyTyp {
ret.Rollup = &av.Rollup{Calc: &av.RollupCalc{Operator: av.CalcOperatorNone}}
}
returnView on GitHub (pinned to 9f775e8a12)