{"record":{"id":"6208cc9d50598da0","repo":"siyuan-note/siyuan","slug":"block-is-required-for-non-detached-rows","errorCode":null,"errorMessage":"--block is required for non-detached rows","messagePattern":"--block is required for non-detached rows","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":258,"sourceCode":"}\n\nvar databaseItemAddCmd = &cobra.Command{\n\tUse:   \"add --av <avID>\",\n\tShort: \"Add a row to database\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tcontent, _ := cmd.Flags().GetString(\"content\")\n\t\tblockID, _ := cmd.Flags().GetString(\"block\")\n\t\tviewID, _ := cmd.Flags().GetString(\"view\")\n\t\tgroupID, _ := cmd.Flags().GetString(\"group\")\n\t\tpreviousID, _ := cmd.Flags().GetString(\"previous\")\n\t\tisDetached, _ := cmd.Flags().GetBool(\"detached\")\n\t\tignoreFill, _ := cmd.Flags().GetBool(\"ignore-default-fill\")\n\t\tif avID == \"\" {\n\t\t\treturn fmt.Errorf(\"--av is required\")\n\t\t}\n\t\tif !isDetached && blockID == \"\" {\n\t\t\treturn fmt.Errorf(\"--block is required for non-detached rows\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would add row to database %s\\n\", avID)\n\t\t\treturn nil\n\t\t}\n\n\t\tsrc := map[string]any{\n\t\t\t\"isDetached\": isDetached,\n\t\t}\n\t\tif blockID != \"\" {\n\t\t\tsrc[\"id\"] = blockID\n\t\t}\n\t\tif content != \"\" {\n\t\t\tsrc[\"content\"] = content\n\t\t}\n\t\tsrcs := []map[string]any{src}\n","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/database.go#L240-L276","documentation":"The `siyuan database item add` command supports two row modes: bound to an existing block (`--block`) or detached (`--detached`). When the row is NOT detached, blockID is mandatory because the kernel creates a bound attribute-view entry anchored to that block; RunE returns this error when `--detached` is absent and `--block` is empty.","triggerScenarios":"Running `siyuan database item add --av <avID>` without either `--block <blockID>` or the `--detached` boolean flag. Also triggered by `--detached=false` with no `--block`.","commonSituations":"Adding a detached-style row but forgetting the `--detached` switch; intending to bind a block but forgetting to copy its block ID; scripts that conditionally pass --block but always omit --detached.","solutions":["If the row should be bound to a block, pass its ID: `--block <blockID>`","If the row should be standalone, add the `--detached` flag","If `--block` comes from a variable, verify the variable is non-empty (e.g. `: \"${BLOCK_ID:?}\"` in bash) before invoking"],"exampleFix":"// before\nsiyuan database item add --av $AV_ID --content \"todo\"\n// after\nsiyuan database item add --av $AV_ID --content \"todo\" --detached\n// or\nsiyuan database item add --av $AV_ID --block $BLOCK_ID --content \"todo\"","handlingStrategy":"validation","validationCode":"if [ -z \"$BLOCK_ID\" ] && [ \"$DETACHED\" != \"true\" ]; then\n  echo \"provide --block or --detached\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the row mode (bound vs detached) up front and derive the flags from it","Default detached rows for standalone entries to avoid needing a block ID","Keep BLOCK_ID capture and item add in the same script step to avoid empty variables"],"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"}