reflex-dev/reflex · error · ValueError

Annotation of the computed var assigned to the column field

Error message

Annotation of the computed var assigned to the column field should be provided.

What it means

Same requirement as the data field, but for columns: if columns is a computed var with no annotation (type Any), data_table cannot determine its structure and raises this.

Source

Thrown at packages/reflex-components-gridjs/src/reflex_components_gridjs/datatable.py:76

        Raises:
            ValueError: If a pandas dataframe is passed in and columns are also provided.
        """
        data = props.get("data")
        columns = props.get("columns")

        # The annotation should be provided if data is a computed var. We need this to know how to
        # render pandas dataframes.
        if is_computed_var(data) and data._var_type == Any:
            msg = "Annotation of the computed var assigned to the data field should be provided."
            raise ValueError(msg)

        if (
            columns is not None
            and is_computed_var(columns)
            and columns._var_type == Any
        ):
            msg = "Annotation of the computed var assigned to the column field should be provided."
            raise ValueError(msg)

        # If data is a pandas dataframe and columns are provided throw an error.
        if (
            types.is_dataframe(type(data))
            or (isinstance(data, Var) and types.is_dataframe(data._var_type))
        ) and columns is not None:
            msg = "Cannot pass in both a pandas dataframe and columns to the data_table component."
            raise ValueError(msg)

        # If data is a list and columns are not provided, throw an error
        if (
            (isinstance(data, Var) and types.typehint_issubclass(data._var_type, list))
            or isinstance(data, list)
        ) and columns is None:
            msg = "column field should be specified when the data field is a list type"
            raise ValueError(msg)

        # Create the component.

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Annotate the columns computed var with its concrete type, e.g. -> list[dict[str, Any]] or -> list[rx.gridjs.datatable.Column]
  2. Alternatively pass columns as a static list

Example fix

# before
@rx.var
def cols(self):
    return [{"name": c} for c in self.headers]
# after
@rx.var
def cols(self) -> list[dict[str, Any]]:
    return [{"name": c} for c in self.headers]
Defensive patterns

Strategy: type-guard

Validate before calling

if columns is not None and is_computed_var(columns) and columns._var_type is Any:
    raise ValueError('annotate columns computed var')  # fail fast with your own context

Type guard

def columns_var_ok(columns: Any) -> bool:
    return columns is None or not (is_computed_var(columns) and columns._var_type is Any)

Prevention

When it happens

Trigger: Passing an unannotated @rx.var-computed columns to rx.data_table(...): @rx.var def get_columns(self): return [...] with no return type.

Common situations: Generating column definitions dynamically (e.g. from user config) without adding a return annotation.

Related errors


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