{"record":{"id":"980d41efe04bc59e","repo":"siyuan-note/siyuan","slug":"av-and-ids-are-required","errorCode":null,"errorMessage":"--av and --ids are required","messagePattern":"--av and --ids are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":293,"sourceCode":"\t\tsrcs := []map[string]any{src}\n\n\t\tif err := model.AddAttributeViewBlock(nil, srcs, avID, \"\", viewID, groupID, previousID, ignoreFill); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar databaseItemRemoveCmd = &cobra.Command{\n\tUse:   \"remove --av <avID> --ids <id1,id2,...>\",\n\tShort: \"Remove rows from database\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tidsStr, _ := cmd.Flags().GetString(\"ids\")\n\t\tif avID == \"\" || idsStr == \"\" {\n\t\t\treturn fmt.Errorf(\"--av and --ids are required\")\n\t\t}\n\t\tids := strings.Split(idsStr, \",\")\n\t\tfor i := range ids {\n\t\t\tids[i] = strings.TrimSpace(ids[i])\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would remove %d row(s) from database %s\\n\", len(ids), avID)\n\t\t\treturn nil\n\t\t}\n\n\t\tif err := model.RemoveAttributeViewBlock(ids, avID); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/database.go#L275-L311","documentation":"The `siyuan database item remove` command requires both the target attribute-view ID (`--av`) and a comma-separated list of row IDs (`--ids`). RunE validates both at once and returns this combined error when either is empty. The ids are later split on commas and trimmed, but empty overall input is rejected first.","triggerScenarios":"Running `siyuan database item remove` with `--av` omitted, with `--ids` omitted, or both. Only overall-empty idsStr is rejected here; an ids string of only commas/whitespace passes this check.","commonSituations":"Building the remove command in a script where the ids variable was never populated from a previous query; forgetting to pass --av while iterating row IDs; deleting a command line's flags during manual testing.","solutions":["Pass both flags: `siyuan database item remove --av <avID> --ids <id1,id2,...>`","Obtain row IDs from a previous database query or by inspecting the attribute view before constructing the command","Guard the script so it aborts when AV_ID or ROW_IDS is unset rather than invoking with empty values"],"exampleFix":"// before\nsiyuan database item remove --ids \"$ROW_IDS\"\n// after\nsiyuan database item remove --av \"$AV_ID\" --ids \"$ROW_IDS\"","handlingStrategy":"validation","validationCode":"if [ -z \"$AV_ID\" ] || [ -z \"$ROW_IDS\" ]; then\n  echo \"both --av and --ids are required\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Query row IDs immediately before removal so the list is fresh and non-empty","Assert both variables non-empty before invoking the CLI","Prefer dry-run (`--dry-run`) to confirm flags resolved before the real removal"],"tags":["cli","validation","database","missing-flag"],"backgroundTag":"missing-required-flag","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"}