siyuan-note/siyuan · error

attribute view is required

Error message

attribute view is required

What it means

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.

Solutions

  1. Construct or obtain the attribute view (e.g. via av.NewAttributeView) before calling configureCreatedAttributeView
  2. Check the error of the preceding creation step and return early instead of proceeding with a nil view
  3. If the nil arises inside CreateAttributeViewDatabase, investigate the earlier av creation call's error

Example fix

// before
var attrView *av.AttributeView
err := configureCreatedAttributeView(attrView, name, pk, keys)
// after
attrView, err := av.NewAttributeView(avID)
if err != nil { return err }
err = configureCreatedAttributeView(attrView, name, pk, keys)
Defensive patterns

Strategy: type-guard

Validate before calling

if attrView == nil { return errors.New("attribute view must be created before configuration") }

Type guard

func hasAttrView(v *av.AttributeView) bool { return v != nil }

Try / catch

if err := configureCreatedAttributeView(attrView, ...); err != nil {
    if err.Error() == "attribute view is required" { return createAttrViewFirst() }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/3c80f0d77a6e3f3c. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view_create.go:126

	view, viewErr := attrView.GetFirstView()
	if nil != viewErr {
		return nil, databaseCreationError(viewErr, cleanupCreatedAttributeView(blockID, avID))
	}
	if err = SetDatabaseBlockView(blockID, avID, view.ID); nil != err {
		return nil, databaseCreationError(err, cleanupCreatedAttributeView(blockID, avID))
	}

	if bt := treenode.GetBlockTree(blockID); nil != bt {
		util.PushReloadProtyle(bt.RootID)
	}
	ReloadAttrView(avID)
	ret = &AttributeViewCreateResult{BlockID: blockID, AvID: avID, ViewID: view.ID, AttributeView: attrView}
	return
}

func configureCreatedAttributeView(attrView *av.AttributeView, name, primaryKeyName string, preparedKeys []*av.Key) (err error) {
	if nil == attrView {
		return errors.New("attribute view is required")
	}
	currentView, err := attrView.GetFirstView()
	if nil != err {
		return
	}
	blockKeyValues := attrView.GetBlockKeyValues()
	if nil == blockKeyValues || nil == blockKeyValues.Key {
		return errors.New("attribute view has no primary key field")
	}

	if name = strings.TrimSpace(name); "" != name {
		name = strings.ReplaceAll(name, "\n", " ")
		if 512 < utf8.RuneCountInString(name) {
			name = string([]rune(name)[:512])
		}
		attrView.Name = name
	}
	if primaryKeyName = strings.TrimSpace(primaryKeyName); "" != primaryKeyName {

View on GitHub (pinned to 9f775e8a12)