siyuan-note/siyuan · error

--av, --key, --item and --value are required

Error message

--av, --key, --item and --value are required

What it means

The `siyuan database item update` command requires four flags identifying the cell and its new value: `--av` (attribute-view ID), `--key` (column/key ID), `--item` (row ID), and `--value` (JSON object for the cell value). RunE rejects the invocation with this combined error if any of the four is empty.

Solutions

  1. Supply all four flags: `siyuan database item update --av <avID> --key <keyID> --item <itemID> --value '{...}'`
  2. Find the key (column) ID and row (item) ID from the database structure before updating
  3. Run with `--dry-run` first to confirm the target cell is resolved without writing

Example fix

// before
siyuan database item update --av $AV_ID --item $ROW_ID --value '{"type":"text","text":"done"}'
// after
siyuan database item update --av $AV_ID --key $KEY_ID --item $ROW_ID --value '{"type":"text","text":"done"}'
Defensive patterns

Strategy: validation

Validate before calling

for v in "$AV_ID" "$KEY_ID" "$ITEM_ID" "$VALUE"; do
  [ -n "$v" ] || { echo "--av, --key, --item, --value all required" >&2; exit 1; }
done

Prevention

When it happens

Trigger: Running `siyuan database item update` with any one (or more) of --av, --key, --item, --value missing or empty-string. Partial invocations like only `--av --item` are rejected identically.

Common situations: Interactive shell history edits dropping one flag; scripts where the key ID was hardcoded for one database but the script was reused against another; forgetting `--value` when only intending a dry-run; long command lines that visually overflow and a flag gets lost.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/632fe73e00a38e69. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/database.go:323

		if err := model.RemoveAttributeViewBlock(ids, avID); err != nil {
			return err
		}
		model.AppendPushReloadAttrViewEntry(avID)
		fmt.Println("ok")
		return nil
	},
}

var databaseItemUpdateCmd = &cobra.Command{
	Use:   "update --av <avID> --key <keyID> --item <itemID> --value <json>",
	Short: "Update a cell value",
	RunE: func(cmd *cobra.Command, args []string) error {
		avID, _ := cmd.Flags().GetString("av")
		keyID, _ := cmd.Flags().GetString("key")
		itemID, _ := cmd.Flags().GetString("item")
		valueStr, _ := cmd.Flags().GetString("value")
		if avID == "" || keyID == "" || itemID == "" || valueStr == "" {
			return fmt.Errorf("--av, --key, --item and --value are required")
		}
		var valueData map[string]any
		if err := json.Unmarshal([]byte(valueStr), &valueData); err != nil {
			return fmt.Errorf("invalid JSON: %s", err)
		}

		if dryRun {
			fmt.Printf("[dry-run] Would update cell in database %s: key=%s item=%s\n", avID, keyID, itemID)
			return nil
		}

		if _, err := model.UpdateAttributeViewCell(nil, avID, keyID, itemID, valueData); err != nil {
			return err
		}
		model.AppendPushReloadAttrViewEntry(avID)
		fmt.Println("ok")
		return nil
	},

View on GitHub (pinned to 9f775e8a12)