{"record":{"id":"f2c729ff7f74a0d8","repo":"siyuan-note/siyuan","slug":"previous-id-and-next-id-cannot-both-be-specified","errorCode":null,"errorMessage":"previous ID and next ID cannot both be specified","messagePattern":"previous ID and next ID cannot both be specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":55,"sourceCode":"\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\n\tpreparedKeys := make([]*av.Key, 0, len(keySpecs))\n\tfor _, spec := range keySpecs {\n\t\tif nil == spec || \"\" == strings.TrimSpace(spec.Name) || \"\" == strings.TrimSpace(spec.Type) {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_create.go#L37-L73","documentation":"CreateAttributeViewDatabase accepts an optional insertion position: either previousID (insert after this block) or nextID (insert before this block), but never both. Specifying both is ambiguous, so the function rejects the call upfront. This is a mutually-exclusive-options guard on the position parameters.","triggerScenarios":"Calling CreateAttributeViewDatabase with both previousID and nextID set to non-empty values; API handler databaseCreate forwarding both fields from a request that filled both.","commonSituations":"Client code copying an insertion struct that carries both neighbors; generic UI logic that always populates both fields; scripts that set the previous sibling and next sibling at once.","solutions":["Set only previousID (insert after it) or only nextID (insert before it); leave the other empty","To insert at a specific position choose the neighbor that matches your intent and null out the other parameter","If you need both bounds for validation, validate yourself first, then pass just one neighbor"],"exampleFix":"// before\nmodel.CreateAttributeViewDatabase(parentID, prevID, nextID, name, pk, layout, keys)\n// after\nprevArg := prevID\nnextArg := \"\"\nmodel.CreateAttributeViewDatabase(parentID, prevArg, nextArg, name, pk, layout, keys)","handlingStrategy":"validation","validationCode":"if previousID != \"\" && nextID != \"\" { return errors.New(\"specify only one of previousID/nextID\") }\nerr := model.CreateAttributeViewDatabase(parentID, previousID, nextID, name, pk, layout, keys)","typeGuard":null,"tryCatchPattern":"result, err := model.CreateAttributeViewDatabase(parentID, previousID, nextID, ...)\nif err != nil && strings.Contains(err.Error(), \"cannot both be specified\") {\n    nextID = \"\" // retry with previousID only\n    result, err = model.CreateAttributeViewDatabase(parentID, previousID, \"\", ...)\n}","preventionTips":["Model insertion position as a single optional neighbor field in your UI/API layer","Zero out the unused neighbor before calling","Add a unit test asserting one-of semantics"],"tags":["validation","api","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","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"}