{"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":6960,"sourceCode":"\t}\n\treturn\n}\n\nfunc AddAttributeViewKey(avID, blockID, keyID, keyName, keyType, keyIcon, previousKeyID string, dateFormat av.DateDisplayFormat) (err error) {\n\tattrView, err := av.ParseAttributeView(avID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tcurrentView, err := getAttrViewViewByBlockID(attrView, blockID)\n\tif nil != err {\n\t\treturn\n\t}\n\n\tkeyTyp := av.KeyType(keyType)\n\tswitch keyTyp {\n\tcase av.KeyTypeBlock:\n\t\treturn 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\n\t\tkey := av.NewKey(keyID, keyName, filterAttrViewIconValue(keyIcon), keyTyp)\n\t\tif av.KeyTypeDate == keyTyp || av.KeyTypeCreated == keyTyp || av.KeyTypeUpdated == keyTyp {\n\t\t\tif !dateFormat.IsValid() {\n\t\t\t\treturn errors.New(\"invalid date display format\")\n\t\t\t}\n\t\t\tkey.DateFormat = dateFormat\n\t\t}\n\t\tif av.KeyTypeRollup == keyTyp {\n\t\t\tkey.Rollup = &av.Rollup{Calc: &av.RollupCalc{Operator: av.CalcOperatorNone}}\n\t\t}\n\n\t\tattrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: key})\n\n\t\tfor _, view := range attrView.Views {","sourceCodeStart":6942,"sourceCodeEnd":6978,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L6942-L6978","documentation":"Thrown by AddAttributeViewKey when the requested key type is KeyTypeBlock. The block key is the AV's primary key and is auto-created exactly once when the AV is initialized; user code is not allowed to add a second primary key. Any attempt to add a column of type 'block' is rejected.","triggerScenarios":"A frontend or API caller issues an addAttrViewKey operation with type 'block'. This can happen due to a UI bug that lists block as an addable type, a script replaying a recorded operation set verbatim, or a plugin that tries to clone the primary key.","commonSituations":"Plugin/automation that copies all key types including the primary; a dropdown that mistakenly exposes 'block'; an import pipeline that re-inserts every column from a source AV.","solutions":["Exclude KeyTypeBlock from the list of user-addable key types in the UI and any import/clone logic.","When cloning an AV's schema, skip the block key (it is created implicitly with the new AV).","Validate operation.Typ != 'block' on the client before sending the add-column transaction."],"exampleFix":"// before\naddAttrViewKey({ type: 'block', ... })\n// after\nconst ADDABLE = ['text','number','date','select','mSelect','url','email','phone','mAsset','template','created','updated','checkbox','relation','rollup','lineNumber']\nif (!ADDABLE.includes(type)) throw new Error(`cannot add key of type ${type}`)\naddAttrViewKey({ type, ... })","handlingStrategy":"validation","validationCode":"const ADDABLE_TYPES = ['text','number','date','select','mSelect','url','email','phone','mAsset','template','created','updated','checkbox','relation','rollup','lineNumber']\nif (!ADDABLE_TYPES.includes(op.type)) { /* reject 'block' and unknown types before sending */ }","typeGuard":"type AddableKeyType = Exclude<av.KeyType, 'block'>\nconst ADDABLE: AddableKeyType[] = ['text','number','date','select','mSelect','url','email','phone','mAsset','template','created','updated','checkbox','relation','rollup','lineNumber']\nfunction isAddableType(t: string): t is AddableKeyType { return (ADDABLE as string[]).includes(t) }","tryCatchPattern":null,"preventionTips":["Exclude 'block' from the add-column UI.","When cloning an AV schema, skip the primary key."],"tags":["attribute-view","primary-key","add-column","validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}