{"record":{"id":"2a9b141d516f4484","repo":"reflex-dev/reflex","slug":"literalvar-subclasses-must-implement-the-var-valu","errorCode":null,"errorMessage":"LiteralVar subclasses must implement the _var_value property.","messagePattern":"LiteralVar subclasses must implement the _var_value property\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/base.py","lineNumber":1811,"sourceCode":"                serialized_value\n            )\n\n        if dataclasses.is_dataclass(value) and not isinstance(value, type):\n            return LiteralObjectVar._get_all_var_data_without_creating_var({\n                k.name: (None if callable(v := getattr(value, k.name)) else v)\n                for k in dataclasses.fields(value)\n            })\n\n        if isinstance(value, range):\n            return None\n\n        msg = f\"Unsupported type {type(value)} for LiteralVar. Tried to create a LiteralVar from {value}.\"\n        raise TypeError(msg)\n\n    @property\n    def _var_value(self) -> Any:\n        msg = \"LiteralVar subclasses must implement the _var_value property.\"\n        raise NotImplementedError(msg)\n\n    def json(self) -> str:\n        \"\"\"Serialize the var to a JSON string.\n\n        Raises:\n            NotImplementedError: If the method is not implemented.\n        \"\"\"\n        msg = \"LiteralVar subclasses must implement the json method.\"\n        raise NotImplementedError(msg)\n\n\n@serializers.serializer\ndef serialize_literal(value: LiteralVar):\n    \"\"\"Serialize a Literal type.\n\n    Args:\n        value: The Literal to serialize.\n","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/base.py#L1793-L1829","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"# before\nclass MyLiteralVar(rx.vars.LiteralVar):\n    def __init__(self, value):\n        self.value = value\n\n# after\nclass MyLiteralVar(rx.vars.LiteralVar):\n    def __init__(self, value):\n        self.value = value\n\n    @property\n    def _var_value(self):\n        return self.value","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from reflex.vars.base import LiteralVar\n\ndef has_var_value(v: LiteralVar) -> bool:\n    return type(v)._var_value is not LiteralVar._var_value and getattr(type(v), '_var_value', None) is not None","tryCatchPattern":"try:\n    val = lit._var_value\nexcept NotImplementedError:\n    # subclass incomplete; fall back to string form or fix the subclass\n    val = str(lit)","preventionTips":["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"],"tags":["reflex","internal-api","subclassing","notimplementederror","vars"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}