reflex-dev/reflex · error · ValueError
The condition must be set
Error message
The condition must be set
What it means
The first argument to `rx.match` must be convertible to a Var. If `LiteralVar.create(cond)` returns None (None condition or an unsupported type), the condition is unusable and match cannot compare against any cases.
Source
Thrown at packages/reflex-components-core/src/reflex_components_core/core/match.py:82
@classmethod
def _create_condition_var(cls, cond: Any) -> Var:
"""Convert the condition to a Var.
Args:
cond: The condition.
Returns:
The condition as a base var
Raises:
ValueError: If the condition is not provided.
"""
match_cond_var = LiteralVar.create(cond)
if match_cond_var is None:
msg = "The condition must be set"
raise ValueError(msg)
return match_cond_var
@classmethod
def _process_cases(
cls, cases: list
) -> tuple[list[tuple], Var | BaseComponent | None]:
"""Process the list of match cases and the catchall default case.
Args:
cases: The list of match cases.
Returns:
The default case and the list of match case tuples.
Raises:
ValueError: If there are multiple default cases.
"""
if not cases:View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Pass a State var or literal: rx.match(State.kind, ...)
- Guard None first: rx.match(cond or 'default', ...) or wrap with rx.cond(cond is not None, rx.match(cond, ...), fallback)
- Use values of supported types (str/int/bool/Var/comparisons)
Example fix
# before
rx.match(get_status(), ('ok', 'OK'), 'other') # may return None
# after
rx.match(State.status or 'unknown', ('ok', 'OK'), 'other') Defensive patterns
Strategy: type-guard
Validate before calling
cond_var = State.kind if State.kind is not None else 'default'
result = rx.match(cond_var, ('a', 1), 0) Type guard
def is_matchable(c) -> bool:
return c is not None and isinstance(c, (str, int, float, bool, Var)) Prevention
- Guard optional match conditions against None
- Match on typed state vars or literals only
When it happens
Trigger: `rx.match(None, ...)`; passing a raw Python object LiteralVar can't serialize (arbitrary class instance, file handle); a refactor leaves the condition expression blank.
Common situations: Matching on an optional field that may be None without a guard; passing untyped API payloads directly as the match condition.
Related errors
- For cases with return types as Vars, a default case must be
- rx.match should have at least one case.
- rx.match should have tuples of cases and one default case as
- A case tuple should have at least a match case element and a
- Match condition {condition_index} of case {case_index} canno
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/ff8dbcb5d7846571.
Report an issue: GitHub.