{"record":{"id":"6af61f5c922f334a","repo":"siyuan-note/siyuan","slug":"parent-id-is-required","errorCode":null,"errorMessage":"parent ID is required","messagePattern":"parent ID is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":52,"sourceCode":"type AttributeViewCreateKey struct {\n\tName string `json:\"name\"`\n\tType string `json:\"type\"`\n\tIcon string `json:\"icon,omitempty\"`\n}\n\n// AttributeViewCreateResult 描述创建数据库后可供调用方继续操作的标识和数据。\ntype AttributeViewCreateResult struct {\n\tBlockID       string\n\tAvID          string\n\tViewID        string\n\tAttributeView *av.AttributeView\n}\n\n// CreateAttributeViewDatabase 创建数据库块和对应属性视图，并按照 keySpecs 的顺序初始化字段。\nfunc CreateAttributeViewDatabase(parentID, previousID, nextID, name, primaryKeyName string, layout av.LayoutType,\n\tkeySpecs []*AttributeViewCreateKey) (ret *AttributeViewCreateResult, err error) {\n\tif \"\" == parentID {\n\t\treturn nil, errors.New(\"parent ID is required\")\n\t}\n\tif \"\" != previousID && \"\" != nextID {\n\t\treturn nil, errors.New(\"previous ID and next ID cannot both be specified\")\n\t}\n\tif \"\" == previousID && \"\" == nextID {\n\t\tif err = treenode.CheckContainerParent(parentID); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tif \"\" == layout {\n\t\tlayout = av.LayoutTypeTable\n\t}\n\tswitch layout {\n\tcase av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:\n\tdefault:\n\t\treturn nil, av.ErrWrongLayoutType\n\t}\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_create.go#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a valid parent block ID (document ID or container block ID) as parentID","Resolve the target document ID first (e.g. via createDocWithMd or the current active doc) before calling the API","In API clients, validate parentID is a non-empty string before sending the request"],"exampleFix":"// before\nmodel.CreateAttributeViewDatabase(\"\", \"\", \"\", \"Tasks\", \"Name\", av.LayoutTypeTable, keys)\n// after\nparentID := \"20240101120000-abcdefg\"\nmodel.CreateAttributeViewDatabase(parentID, \"\", \"\", \"Tasks\", \"Name\", av.LayoutTypeTable, keys)","handlingStrategy":"validation","validationCode":"if parentID == \"\" { return errors.New(\"choose a parent document or container block first\") }\nerr := model.CreateAttributeViewDatabase(parentID, \"\", \"\", name, pk, layout, keys)","typeGuard":null,"tryCatchPattern":"av, err := model.CreateAttributeViewDatabase(parentID, \"\", \"\", name, pk, layout, keys)\nif err != nil {\n    if err.Error() == \"parent ID is required\" { return selectParentDialog() }\n    return err\n}","preventionTips":["Always resolve the parent document/container ID before building the request","Validate non-empty IDs on the client before calling the kernel API","Avoid storing parent IDs in variables that may default to empty string"],"tags":["validation","api","missing-argument"],"backgroundTag":"missing-required-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"}