{"record":{"id":"bfb91c28bd11b35f","repo":"reflex-dev/reflex","slug":"event-key-only-provides-number-of-event-args-a","errorCode":null,"errorMessage":"Event {key} only provides {number_of_event_args} arguments, but {func_name or user_func} requires at least {number_of_user_args - number_of_user_default_args} arguments to be passed to the event handler.\\nSee https://reflex.dev/docs/events/event-arguments/","messagePattern":"Event (.+?) only provides (.+?) arguments, but (.+?) requires at least (.+?) arguments to be passed to the event handler\\.\\\\nSee https://reflex\\.dev/docs/events/event-arguments/","errorType":"exception","errorClass":"EventFnArgMismatchError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/event/__init__.py","lineNumber":2269,"sourceCode":"\n    user_default_args = [\n        p.default\n        for p in user_func_parameters.values()\n        if p.default is not inspect.Parameter.empty\n    ]\n    number_of_user_args = len(user_args) - number_of_bound_args\n    number_of_user_default_args = len(user_default_args) if user_default_args else 0\n\n    number_of_event_args = len(event_spec_args)\n\n    if number_of_user_args - number_of_user_default_args > number_of_event_args:\n        msg = (\n            f\"Event {key} only provides {number_of_event_args} arguments, but \"\n            f\"{func_name or user_func} requires at least {number_of_user_args - number_of_user_default_args} \"\n            \"arguments to be passed to the event handler.\\n\"\n            \"See https://reflex.dev/docs/events/event-arguments/\"\n        )\n        raise EventFnArgMismatchError(msg)\n\n\ndef call_event_fn(\n    fn: Callable,\n    arg_spec: ArgsSpec | Sequence[ArgsSpec],\n    key: str | None = None,\n) -> list[\"EventSpec | FunctionVar | EventVar\"]:\n    \"\"\"Call a function to a list of event specs.\n\n    The function should return a single event-like value or a heterogeneous\n    sequence of event-like values.\n\n    Args:\n        fn: The function to call.\n        arg_spec: The argument spec for the event trigger.\n        key: The key to pass to the event handler.\n\n    Returns:","sourceCodeStart":2251,"sourceCodeEnd":2287,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/event/__init__.py#L2251-L2287","documentation":"When a component event (with a fixed args_spec, e.g. on_change providing one value) is bound to a user function via call_event_fn/call_event_handler, Reflex verifies the event supplies enough arguments for the function's required parameters. Too few event args versus required (non-default) parameters raises EventFnArgMismatchError, with a link to the event-arguments docs.","triggerScenarios":"Passing a lambda/function to a trigger that expects the callback to accept the event's args: e.g. using a trigger that provides 1 argument with a function requiring 2 positional params without defaults (lambda a, b: ...).","commonSituations":"Handling input events (which supply one value) with multi-arg handlers; changing a handler signature to add required params while it stays bound to a single-arg event; passing state handlers with required args to argless events like on_mount.","solutions":["Give the extra parameters default values so the event's arg count suffices: def on_change(self, value: str, flag: bool = False)","Match the handler arity to the event's args_spec (check the docs link in the message)","For extra context, capture it in state or via closure instead of extra required params"],"exampleFix":"# before\nclass State(rx.State):\n    @rx.event\n    def on_change(self, value: str, source: str): ...\n# after\nclass State(rx.State):\n    @rx.event\n    def on_change(self, value: str, source: str = 'input'): ...","handlingStrategy":"validation","validationCode":"import inspect\n\ndef arity_ok(fn, n_event_args) -> bool:\n    sig = inspect.signature(fn)\n    req = sum(1 for p in sig.parameters.values() if p.default is p.empty and p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD))\n    return req <= n_event_args","typeGuard":"def accepts_event_args(fn, n) -> TypeGuard[Callable]: return arity_ok(fn, n)","tryCatchPattern":null,"preventionTips":["Give optional context params default values in event handlers","Check the component's args_spec (docs) before binding handlers with multiple required args"],"tags":["reflex","event-handler","arity-mismatch","callback"],"backgroundTag":"callback-argument-count-mismatch","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}