reflex-dev/reflex · error · ValueError

Function for {generic_type} already registered.

Error message

Function for {generic_type} already registered.

What it means

The operator dispatcher table already contains a function for the given generic type, so registering a second one is rejected to keep dispatch unambiguous.

Source

Thrown at packages/reflex-base/src/reflex_base/vars/base.py:3373

    return_type = types["return"]

    origin = get_origin(return_type)

    if origin is not Var:
        msg = f"Expected return type of {fn.__name__} to be a Var, got {origin}."
        raise TypeError(msg)

    generic_args = get_args(return_type)

    if not generic_args:
        msg = f"Expected Var return type of {fn.__name__} to have a generic type."
        raise TypeError(msg)

    generic_type = get_origin(generic_args[0]) or generic_args[0]

    if generic_type in dispatchers:
        msg = f"Function for {generic_type} already registered."
        raise ValueError(msg)

    dispatchers[generic_type] = fn

    return fn


def dispatch(
    field_name: str,
    var_data: VarData,
    result_var_type: GenericType,
    existing_var: Var | None = None,
) -> Var:
    """Dispatch a Var to the appropriate transformation function.

    Args:
        field_name: The name of the field.
        var_data: The VarData associated with the Var.
        result_var_type: The type of the Var.

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Check dispatchers for the existing registration and extend that function instead of adding a new one
  2. Give the new function a distinct generic return type or rename/reuse the existing entry
  3. Guard registration with an `if generic_type not in dispatchers` check in test/dev code
Defensive patterns

Strategy: validation

Validate before calling

from typing import get_origin, get_args
key = get_origin(get_args(fn.__annotations__['return'])[0]) or get_args(fn.__annotations__['return'])[0]
if key in dispatchers:
    # extend existing dispatcher instead of re-registering
    ...

Prevention

When it happens

Trigger: Registering two dispatch functions whose return Var[T] generic type is the same (e.g. two functions returning Var[str]) in the same process.

Common situations: A module registering a custom operator gets imported twice with different definitions, or a user re-registers an operator reflex already provides (e.g. adding another Var[str] formatter).

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/fa3472da500bc5fe. Report an issue: GitHub.