siyuan-note/siyuan · error

parent ID is required

Error message

parent ID is required

What it means

CreateAttributeViewDatabase requires a parentID identifying the container block (e.g. a document or a superblock) into which the new database block will be inserted. If parentID is the empty string the function fails immediately with this error before any validation of position or layout. It is a fail-fast guard for a missing required positional argument.

Solutions

  1. Pass a valid parent block ID (document ID or container block ID) as parentID
  2. Resolve the target document ID first (e.g. via createDocWithMd or the current active doc) before calling the API
  3. In API clients, validate parentID is a non-empty string before sending the request

Example fix

// before
model.CreateAttributeViewDatabase("", "", "", "Tasks", "Name", av.LayoutTypeTable, keys)
// after
parentID := "20240101120000-abcdefg"
model.CreateAttributeViewDatabase(parentID, "", "", "Tasks", "Name", av.LayoutTypeTable, keys)
Defensive patterns

Strategy: validation

Validate before calling

if parentID == "" { return errors.New("choose a parent document or container block first") }
err := model.CreateAttributeViewDatabase(parentID, "", "", name, pk, layout, keys)

Try / catch

av, err := model.CreateAttributeViewDatabase(parentID, "", "", name, pk, layout, keys)
if err != nil {
    if err.Error() == "parent ID is required" { return selectParentDialog() }
    return err
}

Prevention

When it happens

Trigger: Calling CreateAttributeViewDatabase (or the API handler databaseCreate that wraps it) with parentID="", e.g. the client never resolved a document/block ID, or an empty field was serialized in the request payload.

Common situations: Plugin or script building the API request with an unset variable; frontend passing an empty docID when no document is open; API consumers omitting the parentID field in the request body.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/attribute_view_create.go:52

type AttributeViewCreateKey struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Icon string `json:"icon,omitempty"`
}

// AttributeViewCreateResult 描述创建数据库后可供调用方继续操作的标识和数据。
type AttributeViewCreateResult struct {
	BlockID       string
	AvID          string
	ViewID        string
	AttributeView *av.AttributeView
}

// CreateAttributeViewDatabase 创建数据库块和对应属性视图,并按照 keySpecs 的顺序初始化字段。
func CreateAttributeViewDatabase(parentID, previousID, nextID, name, primaryKeyName string, layout av.LayoutType,
	keySpecs []*AttributeViewCreateKey) (ret *AttributeViewCreateResult, err error) {
	if "" == parentID {
		return nil, errors.New("parent ID is required")
	}
	if "" != previousID && "" != nextID {
		return nil, errors.New("previous ID and next ID cannot both be specified")
	}
	if "" == previousID && "" == nextID {
		if err = treenode.CheckContainerParent(parentID); nil != err {
			return nil, err
		}
	}
	if "" == layout {
		layout = av.LayoutTypeTable
	}
	switch layout {
	case av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:
	default:
		return nil, av.ErrWrongLayoutType
	}

View on GitHub (pinned to 9f775e8a12)