{"record":{"id":"678b954936563bed","repo":"siyuan-note/siyuan","slug":"attribute-view-has-no-primary-key-field","errorCode":null,"errorMessage":"attribute view has no primary key field","messagePattern":"attribute view has no primary key field","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":134,"sourceCode":"\tif bt := treenode.GetBlockTree(blockID); nil != bt {\n\t\tutil.PushReloadProtyle(bt.RootID)\n\t}\n\tReloadAttrView(avID)\n\tret = &AttributeViewCreateResult{BlockID: blockID, AvID: avID, ViewID: view.ID, AttributeView: attrView}\n\treturn\n}\n\nfunc configureCreatedAttributeView(attrView *av.AttributeView, name, primaryKeyName string, preparedKeys []*av.Key) (err error) {\n\tif nil == attrView {\n\t\treturn errors.New(\"attribute view is required\")\n\t}\n\tcurrentView, err := attrView.GetFirstView()\n\tif nil != err {\n\t\treturn\n\t}\n\tblockKeyValues := attrView.GetBlockKeyValues()\n\tif nil == blockKeyValues || nil == blockKeyValues.Key {\n\t\treturn errors.New(\"attribute view has no primary key field\")\n\t}\n\n\tif name = strings.TrimSpace(name); \"\" != name {\n\t\tname = strings.ReplaceAll(name, \"\\n\", \" \")\n\t\tif 512 < utf8.RuneCountInString(name) {\n\t\t\tname = string([]rune(name)[:512])\n\t\t}\n\t\tattrView.Name = name\n\t}\n\tif primaryKeyName = strings.TrimSpace(primaryKeyName); \"\" != primaryKeyName {\n\t\tblockKeyValues.Key.Name = primaryKeyName\n\t}\n\n\tretainedKeyValues := []*av.KeyValues{blockKeyValues}\n\tretainedKeyIDs := map[string]bool{blockKeyValues.Key.ID: true}\n\tvar kanbanGroupKey *av.Key\n\tif av.LayoutTypeKanban == currentView.LayoutType {\n\t\tfor _, key := range preparedKeys {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/attribute_view_create.go#L116-L152","documentation":"After creating an attribute view, the block key (the primary key column holding block references) must exist before the view can be configured with rows. If GetBlockKeyValues returns nil or a structure without a Key, the view is malformed and configuration cannot continue.","triggerScenarios":"configureCreatedAttributeView receiving an attribute view whose block key was never initialized — e.g. a fixture built in tests without av.NewBlockKeyValues, or a view created through a path that skipped primary-key setup.","commonSituations":"Test fixtures that construct av.AttributeView manually and forget the block key; an upgraded/legacy attribute view JSON missing the primary key; a creation bug in the key-initialization code path.","solutions":["Initialize the block (primary) key on the attribute view before configuring, e.g. via the standard key-setup code used by CreateAttributeViewDatabase","In tests, use the same construction helper the production code uses so the primary key exists","If loading an existing view, re-create or repair it so the block key column is present"],"exampleFix":"// before\nattrView := av.NewAttributeView(avID)\nerr := model.ConfigureCreatedAttributeViewForTest(attrView, name, \"Name\", keys)\n// after\nattrView := av.NewAttributeView(avID)\nattrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: &av.Key{ID: av.NewNodeID(), Name: \"Name\", Type: av.KeyTypeBlock}})\nerr := model.ConfigureCreatedAttributeViewForTest(attrView, name, \"Name\", keys)","handlingStrategy":"validation","validationCode":"if attrView.GetBlockKeyValues() == nil || attrView.GetBlockKeyValues().Key == nil {\n    return errors.New(\"attribute view fixture must define the block (primary) key\")\n}","typeGuard":null,"tryCatchPattern":"if err := configureCreatedAttributeView(attrView, name, pk, keys); err != nil {\n    return fmt.Errorf(\"attribute view missing primary key: %w\", err)\n}","preventionTips":["Always initialize the block key when building an av.AttributeView by hand","Prefer shared construction helpers over ad-hoc fixtures","When loading legacy views, verify the primary key exists before operating on them"],"tags":["internal","attribute-view","primary-key","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}