iflytek/astron-agent · error · ValueError

When mode=2 (UPDATE) or mode=4 (DELETE), cases cannot be…

Error message

When mode=2 (UPDATE) or mode=4 (DELETE), cases cannot be empty.

What it means

Pydantic validator on the `cases` field. UPDATE (mode=2) and DELETE (mode=4) build a WHERE clause from `cases`; with an empty cases list the statement would have no WHERE condition, which is unsafe, so the model rejects construction with a ValueError (pydantic ValidationError).

Solutions

  1. Add at least one Case (column, operator, value) to `cases` for UPDATE/DELETE nodes.
  2. Switch to another mode if an unconditional operation is truly intended (and write explicit SQL in CUSTOM mode after reviewing the risk).
  3. Update the workflow editor to require >=1 condition before enabling save for modes 2 and 4.
  4. Catch and map this ValidationError to a user-facing message about missing WHERE conditions.

Example fix

// before
PgsqlNodeData(mode=4, tableName="users", cases=[])
// after
PgsqlNodeData(mode=4, tableName="users", cases=[Case(column="id", operator="=", value=42)])
Defensive patterns

Strategy: validation

Validate before calling

def validate_cases(node_cfg: dict):
    if node_cfg.get("mode") in (2, 4) and not node_cfg.get("cases"):
        raise ValueError("UPDATE/DELETE require at least one case (WHERE condition)")

Type guard

def has_where_cases(cfg) -> bool:
    return cfg.mode not in (2, 4) or len(cfg.cases) > 0

Try / catch

try:
    node_data = PgsqlNodeData(**cfg)
except ValidationError as e:
    if any("cases cannot be empty" in err["msg"] for err in e.errors()):
        show_field_error("cases", "Add at least one condition for UPDATE/DELETE")
    raise

Prevention

When it happens

Trigger: Constructing PgsqlNodeData with mode=2 or mode=4 and `cases` set to an empty list.

Common situations: Author configures an UPDATE/DELETE node but never adds a condition row; frontend clears conditions on mode switch; imported workflow template with zero conditions.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/8bb87755dbca0f69. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/engine/nodes/pgsql/pgsql_node.py:145

        if mode in (1, 2, 3, 4) and (v is None or v.strip() == ""):
            raise ValueError(f"When mode={mode}, tableName is required.")
        return v

    @field_validator("cases", mode="after")
    def _check_cases_for_update_delete(
        cls, v: List[Case], info: ValidationInfo
    ) -> List[Case]:
        """
        Check if the cases are valid for the given mode.

        :param v: Cases list
        :param info: ValidationInfo
        :return: Cases list
        :raises ValueError: If the cases are invalid
        """
        mode = info.data.get("mode")
        if mode in (2, 4) and not v:
            raise ValueError(
                "When mode=2 (UPDATE) or mode=4 (DELETE), cases cannot be empty."
            )
        return v

    @property
    def run_s(self) -> WorkflowNodeExecutionStatus:
        """Get the success execution status.

        :return: SUCCEEDED status for successful operations
        """
        return WorkflowNodeExecutionStatus.SUCCEEDED

    @property
    def run_f(self) -> WorkflowNodeExecutionStatus:
        """Get the failure execution status.

        :return: FAILED status for failed operations
        """

View on GitHub (pinned to 5e758547a8)