{"record":{"id":"4d0a5cb39c4a0eac","repo":"reflex-dev/reflex","slug":"unexpected-event-type-type-e","errorCode":null,"errorMessage":"Unexpected event type, {type(e)}.","messagePattern":"Unexpected event type, (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/event/__init__.py","lineNumber":147,"sourceCode":"        for e in events:\n            if callable(e) and getattr(e, \"__name__\", \"\") == \"<lambda>\":\n                # A lambda was returned, assume the user wants to call it with no args.\n                e = e()\n            if isinstance(e, Event):\n                # If the event is already an event, append it to the list.\n                if router_data is not None and e.router_data != router_data:\n                    out.append(\n                        dataclasses.replace(e, router_data=e.router_data | router_data)\n                    )\n                else:\n                    out.append(e)\n                continue\n            # Otherwise, create an event from the event spec.\n            if isinstance(e, EventHandler):\n                e = e()\n            if not isinstance(e, EventSpec):\n                msg = f\"Unexpected event type, {type(e)}.\"\n                raise ValueError(msg)\n            name = format.format_event_handler(e.handler)\n            # Detach mutable values from any state-bound proxies (e.g.\n            # ImmutableMutableProxy from a background task's StateProxy),\n            # copying only subtrees that are actually proxied.\n            payload = {\n                k._js_expr: _detach_state_proxies(v._decode()) for k, v in e.args\n            }\n\n            # Create an event and append it to the list.\n            out.append(\n                Event(\n                    name=name,\n                    payload=payload,\n                    router_data=router_data or {},\n                )\n            )\n\n        return out","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/event/__init__.py#L129-L165","documentation":"While converting event specs (e.g. in _apply_handler or event chains), Reflex accepts EventSpec objects and zero-arg EventHandler calls; anything else — a raw function, lambda, string, or arbitrary object — triggers ValueError 'Unexpected event type'. The type of the offending object is included in the message.","triggerScenarios":"Returning or chaining values that aren't events from event handlers/compile targets: returning a plain function reference, a string, or None-adjacent objects where an EventSpec/EventHandler is expected (e.g. mixing rx.event results with raw callables in a list passed to event chaining).","commonSituations":"Forgetting to call an EventHandler, returning a lambda from a handler, or passing an unwrapped user function into an API expecting event specs.","solutions":["Look at {type(e)} in the message to identify the offending value","Wrap plain functions with rx.event / ensure you return EventSpec-producing calls (e.g. call the handler: State.my_handler())","Don't return raw callables/strings from event handlers; map them to event specs first"],"exampleFix":"# before\ndef index():\n    return rx.button(\"Go\", on_click=[State.go, do_something_raw])\n# after\n@rx.event\ndef do_something(): ...\ndef index():\n    return rx.button(\"Go\", on_click=[State.go, do_something])\n","handlingStrategy":"type-guard","validationCode":"from reflex_base.event import EventSpec, EventHandler\nassert all(isinstance(e, (EventSpec, EventHandler)) for e in event_list), f\"non-event in list: {[type(e) for e in event_list]}\"","typeGuard":"def is_event_like(e) -> bool:\n    from reflex_base.event import EventSpec, EventHandler\n    return isinstance(e, (EventSpec, EventHandler))","tryCatchPattern":"null","preventionTips":["Always return rx.event-decorated callables' results from handlers","Type event lists as list[EventSpec] in your own helpers so mypy catches raw callables"],"tags":["events","type-validation","event-handler"],"backgroundTag":"event-type-mismatch","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}