reflex-dev/reflex · error · NotImplementedError
LiteralVar subclasses must implement the _var_value property
Error message
LiteralVar subclasses must implement the _var_value property.
What it means
This NotImplementedError is raised by the base LiteralVar class when code accesses the _var_value property on a LiteralVar subclass that did not override it. _var_value exposes the underlying Python value of the literal; every concrete LiteralVar subclass (NumberVar, StringVar, BooleanVar, etc.) must implement it. It is an internal API contract error, not a user data error.
Source
Thrown at packages/reflex-base/src/reflex_base/vars/base.py:1811
serialized_value
)
if dataclasses.is_dataclass(value) and not isinstance(value, type):
return LiteralObjectVar._get_all_var_data_without_creating_var({
k.name: (None if callable(v := getattr(value, k.name)) else v)
for k in dataclasses.fields(value)
})
if isinstance(value, range):
return None
msg = f"Unsupported type {type(value)} for LiteralVar. Tried to create a LiteralVar from {value}."
raise TypeError(msg)
@property
def _var_value(self) -> Any:
msg = "LiteralVar subclasses must implement the _var_value property."
raise NotImplementedError(msg)
def json(self) -> str:
"""Serialize the var to a JSON string.
Raises:
NotImplementedError: If the method is not implemented.
"""
msg = "LiteralVar subclasses must implement the json method."
raise NotImplementedError(msg)
@serializers.serializer
def serialize_literal(value: LiteralVar):
"""Serialize a Literal type.
Args:
value: The Literal to serialize.
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Implement the _var_value property in your LiteralVar subclass returning the wrapped Python value
- If you don't intend a custom subclass, return an existing LiteralVar type (NumberVar, StringVar, etc.) or a plain JSON value from your serializer instead
- Verify reflex and reflex-base workspace packages are version-matched (uv sync) if you did not subclass anything
Example fix
# before
class MyLiteralVar(rx.vars.LiteralVar):
def __init__(self, value):
self.value = value
# after
class MyLiteralVar(rx.vars.LiteralVar):
def __init__(self, value):
self.value = value
@property
def _var_value(self):
return self.value Defensive patterns
Strategy: type-guard
Type guard
from reflex.vars.base import LiteralVar
def has_var_value(v: LiteralVar) -> bool:
return type(v)._var_value is not LiteralVar._var_value and getattr(type(v), '_var_value', None) is not None Try / catch
try:
val = lit._var_value
except NotImplementedError:
# subclass incomplete; fall back to string form or fix the subclass
val = str(lit) Prevention
- Implement _var_value and json() in every custom LiteralVar subclass
- Cover custom Var subclasses with unit tests that access _var_value and json()
- Prefer returning JSON-safe values from serializers instead of custom LiteralVar subclasses
When it happens
Trigger: Subclassing reflex.vars.base.LiteralVar (or reflex.Var literal classes) without implementing the _var_value property, then accessing instance._var_value; or library code calling _var_value on a partially-constructed/custom LiteralVar via methods like LiteralVar.create round-trips or equality checks.
Common situations: Writing a custom Var/LiteralVar subclass (e.g. for a custom serializer returning your own Var type) and forgetting to implement _var_value; mixing Reflex internal APIs across incompatible package versions (reflex vs reflex-base version skew in a monorepo/workspace).
Related errors
- LiteralVar subclasses must implement the json method.
- Unexpected keyword arguments: {unexpected_kwargs}
- The component `{comp_name}` cannot have `{child_name}` as a
- CallableEventSpec has no associated function.
- Expected _js_expr to be a string, got value {self._js_expr!r
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/2a9b141d516f4484.
Report an issue: GitHub.