{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/attribute_view_create.go#L34-L70","documentation":"CreateAttributeViewDatabase requires a parent block ID so it knows which document/container to insert the new database block into. When parentID is the empty string, there is no valid insertion target, so the function immediately returns this error before doing any work.","triggerScenarios":"Calling CreateAttributeViewDatabase (or the databaseCreate API route) with parentID=\"\" — typically because the caller never resolved the document/block ID from a UI selection, or passed an uninitialized variable.","commonSituations":"Plugin or script automation that creates a database without first obtaining a document ID; a frontend call where the user had no focused document so the parent ID field was never populated; copying example code that omits parentID.","solutions":["Obtain a valid parent block ID first (e.g. the document ID or a container block ID) and pass it as parentID","If inserting relative to a sibling block, use that sibling's parent as parentID and pass the sibling as previousID/nextID","Validate the parent ID is non-empty in the caller before invoking the API"],"exampleFix":"// before\nret, err := model.CreateAttributeViewDatabase(\"\", \"\", nextID, \"DB\", \"Name\", av.LayoutTypeTable, keys)\n// after\nif parentID == \"\" {\n    return errors.New(\"resolve a parent block ID first\")\n}\nret, err := model.CreateAttributeViewDatabase(parentID, \"\", nextID, \"DB\", \"Name\", av.LayoutTypeTable, keys)","handlingStrategy":"validation","validationCode":"if parentID == \"\" {\n    return errors.New(\"cannot create database: parent ID is empty\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always resolve parentID from a real document or container block before calling the API","Have API handlers reject empty parent IDs with a client-friendly message early","Keep a helper that fetches the current focused document ID and fail fast if absent"],"tags":["api","validation","attribute-view","go"],"backgroundTag":"missing-required-argument","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}