{"record":{"id":"3c80f0d77a6e3f3c","repo":"siyuan-note/siyuan","slug":"attribute-view-is-required","errorCode":null,"errorMessage":"attribute view is required","messagePattern":"attribute view is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":126,"sourceCode":"\tview, viewErr := attrView.GetFirstView()\n\tif nil != viewErr {\n\t\treturn nil, databaseCreationError(viewErr, cleanupCreatedAttributeView(blockID, avID))\n\t}\n\tif err = SetDatabaseBlockView(blockID, avID, view.ID); nil != err {\n\t\treturn nil, databaseCreationError(err, cleanupCreatedAttributeView(blockID, avID))\n\t}\n\n\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 {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_create.go#L108-L144","documentation":"configureCreatedAttributeView is the internal step that names the view, orders fields, and sets the primary key on a freshly created attribute view. It requires a non-nil *av.AttributeView; receiving nil means the caller skipped or failed creation but still invoked configuration. It is an internal defensive check rather than a user-facing validation.","triggerScenarios":"Programmatically calling configureCreatedAttributeView directly (tests or internal code) with a nil attrView; a refactor of CreateAttributeViewDatabase that would pass a nil view after a failed creation step.","commonSituations":"Writing unit tests that call the helper without constructing an av.AttributeView first; custom code that builds an attribute view itself and reuses this helper.","solutions":["Construct or obtain the attribute view (e.g. via av.NewAttributeView) before calling configureCreatedAttributeView","Check the error of the preceding creation step and return early instead of proceeding with a nil view","If the nil arises inside CreateAttributeViewDatabase, investigate the earlier av creation call's error"],"exampleFix":"// before\nvar attrView *av.AttributeView\nerr := configureCreatedAttributeView(attrView, name, pk, keys)\n// after\nattrView, err := av.NewAttributeView(avID)\nif err != nil { return err }\nerr = configureCreatedAttributeView(attrView, name, pk, keys)","handlingStrategy":"type-guard","validationCode":"if attrView == nil { return errors.New(\"attribute view must be created before configuration\") }","typeGuard":"func hasAttrView(v *av.AttributeView) bool { return v != nil }","tryCatchPattern":"if err := configureCreatedAttributeView(attrView, ...); err != nil {\n    if err.Error() == \"attribute view is required\" { return createAttrViewFirst() }\n    return err\n}","preventionTips":["Check the error of the creation step before calling the configure helper","Never pass a possibly-nil pointer returned from a failed constructor","Keep helper functions internal; prefer the public CreateAttributeViewDatabase entry point"],"tags":["internal","nil-check","validation"],"backgroundTag":"null-argument","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"}