reflex-dev/reflex · error · ValueError
Invalid event chain: {value!s} of type {value._var_type}
Error message
Invalid event chain: {value!s} of type {value._var_type} What it means
EventChain.create accepts handlers, EventSpecs, EventChains, lists of those, or lambdas; if the value is a Var (has _var_type) it falls through to this branch and is rejected with its type, because a Var is data, not an event chain.
Source
Thrown at packages/reflex-base/src/reflex_base/event/__init__.py:911
if event_chain_kwargs:
warnings.warn(
f"event_chain_kwargs {event_chain_kwargs!r} are ignored for "
"EventChainVar values.",
stacklevel=2,
)
return value
if isinstance(value, (EventVar, FunctionVar)):
value = [value]
elif safe_issubclass(value._var_type, (EventChain, EventSpec)):
return cls.create(
value=value.guess_type(),
args_spec=args_spec,
key=key,
**event_chain_kwargs,
)
else:
msg = f"Invalid event chain: {value!s} of type {value._var_type}"
raise ValueError(msg)
elif isinstance(value, EventChain):
# Trust that the caller knows what they're doing passing an EventChain directly
return value
# If the input is a single event handler, wrap it in a list.
if isinstance(value, (EventHandler, EventSpec)):
value = [value]
events: list[EventSpec | EventVar | FunctionVar] = []
# If the input is a list of event handlers, create an event chain.
if isinstance(value, list):
for v in value:
if isinstance(v, (EventHandler, EventSpec)):
# Call the event handler to get the event.
events.append(call_event_handler(v, args_spec, key=key))
elif isinstance(v, (EventVar, EventChainVar)):
events.append(v)View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Ensure the value is an event handler call, EventSpec, EventChain, or a lambda returning those
- If a lambda returns a Var, wrap the logic so it returns events (e.g. use rx.cond at the component level, not inside the event slot)
- Check for a missing () on the handler invocation
Example fix
# before
rx.button('Go', on_click=State.count) # a Var
# after
rx.button('Go', on_click=State.increment) Defensive patterns
Strategy: type-guard
Validate before calling
from reflex_base.event import EventHandler, EventSpec, EventChain
def is_event_chain_value(v) -> bool:
return isinstance(v, (EventHandler, EventSpec, EventChain, list, tuple)) and not hasattr(v, '_var_type') Type guard
def is_event_trigger(v) -> TypeGuard[object]: return isinstance(v, (EventHandler, EventSpec, EventChain)) or callable(v)
Prevention
- Never assign a bare Var to an event prop
- Review on_* props for missing () when calling handlers
When it happens
Trigger: Passing a Var (e.g. State.some_var or a computed Var) where an event trigger is expected: on_click=State.items, on_click=rx.cond(..., a, b) misuse, or a lambda that returns a Var.
Common situations: Assigning a Var to an event prop by accident (missing parentheses on an event call), or a lambda returning a Var instead of an event.
Related errors
- Invalid event: {v}
- Invalid event chain: {value}
- Var-returning `@rx.memo` `{func_name}` cannot depend on embe
- Invalid prop(s) {invalid_fields_str} for {component_name!r}.
- default_color_mode must be one of {allowed_color_modes}, but
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/954b4ad80959b623.
Report an issue: GitHub.