reflex-dev/reflex · error · TypeError
Unexpected keyword arguments: {unexpected_kwargs}
Error message
Unexpected keyword arguments: {unexpected_kwargs} What it means
ComputedVar._replace rebuilds the var via type(self)(**field_values) and only forwards a known set of fields (fget, initial_value, cache, deps, auto_deps, interval, backend, _js_expr, _var_type/_return_type, etc.). If the dataclass was constructed with extra attribute kwargs that _replace does not propagate, or a caller passes unknown kwargs, the reconstruction raises this TypeError. It indicates an internal/API mismatch in how a ComputedVar is being rebuilt.
Source
Thrown at packages/reflex-base/src/reflex_base/vars/base.py:2465
"fget": kwargs.pop("fget", self._fget),
"initial_value": kwargs.pop("initial_value", self._initial_value),
"cache": kwargs.pop("cache", self._cache),
"deps": kwargs.pop("deps", copy.copy(self._static_deps)),
"auto_deps": kwargs.pop("auto_deps", self._auto_deps),
"interval": kwargs.pop("interval", self._update_interval),
"backend": kwargs.pop("backend", self._backend),
"_js_expr": kwargs.pop("_js_expr", self._js_expr),
"_var_type": kwargs.pop("_var_type", self._var_type),
"_var_data": kwargs.pop(
"_var_data", VarData.merge(self._var_data, merge_var_data)
),
"return_type": kwargs.pop("return_type", self._var_type),
}
if kwargs:
unexpected_kwargs = ", ".join(kwargs.keys())
msg = f"Unexpected keyword arguments: {unexpected_kwargs}"
raise TypeError(msg)
return type(self)(**field_values)
@property
def _cache_attr(self) -> str:
"""The attribute used to cache the value on the instance.
Returns:
An attribute name.
"""
return f"__cached_{self._js_expr}"
@property
def _last_updated_attr(self) -> str:
"""The attribute used to store the last updated timestamp.
Returns:
An attribute name.View on GitHub (pinned to 45b8ed5ab7)
Solutions
- If subclassing ComputedVar, override _replace to include your extra fields, or avoid extra init kwargs
- Run uv sync / align reflex and reflex-base versions so _replace matches the constructor
- Update your fork/vendored copy if you patched ComputedVar fields without updating _replace
Example fix
# before
class MyComputedVar(rx.vars.ComputedVar):
def __init__(self, fget, my_extra=None, **kwargs):
super().__init__(fget, **kwargs)
self.my_extra = my_extra
# later: some_var._replace(merge_var_data=...) -> TypeError
# after
class MyComputedVar(rx.vars.ComputedVar):
def __init__(self, fget, my_extra=None, **kwargs):
super().__init__(fget, **kwargs)
self.my_extra = my_extra
def _replace(self, **kwargs):
kwargs.setdefault('my_extra', self.my_extra)
return super()._replace(**kwargs) Defensive patterns
Strategy: validation
Validate before calling
import inspect
def replace_safe(cv, **kwargs) -> 'ComputedVar':
import reflex.vars as rx_vars
params = set(inspect.signature(type(cv).__init__).parameters)
safe = {k: v for k, v in kwargs.items() if k in params or k in {'merge_var_data', 'partial', 'initial_value', '_js_expr', 'return_type'}}
return cv._replace(**safe) Try / catch
try:
new_var = cv._replace(**opts)
except TypeError as e:
if 'Unexpected keyword arguments' in str(e):
new_var = cv._replace(merge_var_data=opts.get('merge_var_data'))
else:
raise Prevention
- If subclassing ComputedVar, override _replace to forward your custom fields
- Keep reflex and reflex-base workspace versions in sync with uv sync
- Pass only documented _replace kwargs: merge_var_data, partial, initial_value, return_type
When it happens
Trigger: Calling ComputedVar._replace(...) with a kwarg not in its supported set; creating a ComputedVar subclass whose __init__ accepts extra kwargs not handled by _replace, then applying _replace (e.g. during var-data merging in the compiler); version skew where _replace's field list differs from the constructor's accepted kwargs.
Common situations: Subclassing ComputedVar with additional constructor parameters; running mismatched reflex/reflex-base workspace versions so the field list is out of sync; internal compiler paths calling _replace on custom var subclasses.
Related errors
- Expected _js_expr to be a string, got value {self._js_expr!r
- LiteralVar subclasses must implement the _var_value property
- LiteralVar subclasses must implement the json method.
- Unexpected keyword arguments: {tuple(kwargs)}
- ComputedVar dependencies must be Var instances or var names
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/6ac24a47699dcc42.
Report an issue: GitHub.