reflex-dev/reflex · error · VarValueError

Cached var {self!s} cannot access arbitrary state via `{inst

Error message

Cached var {self!s} cannot access arbitrary state via `{instruction.argval}`.

What it means

Cached computed vars may only depend on tracked state attributes; accessing arbitrary state through forbidden attribute names (collected in INVALID_NAMES) is rejected so that dependencies stay statically known.

Source

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

    def load_attr_or_method(self, instruction: dis.Instruction) -> None:
        """Handle loading an attribute or method from the object on top of the stack.

        This method directly tracks attributes and recursively merges
        dependencies from analyzing the dependencies of any methods called.

        Args:
            instruction: The dis instruction to process.

        Raises:
            VarValueError: if the attribute is an disallowed name or attribute
                does not reference a BaseState.
        """
        from .base import ComputedVar

        if instruction.argval in self.INVALID_NAMES:
            msg = f"Cached var {self!s} cannot access arbitrary state via `{instruction.argval}`."
            raise VarValueError(msg)
        if instruction.argval == "get_state":
            # Special case: arbitrary state access requested.
            self.scan_status = ScanStatus.GETTING_STATE
            return
        if instruction.argval == "get_var_value":
            # Special case: arbitrary var access requested.
            if sys.version_info >= (3, 11):
                self._get_var_value_positions = instruction.positions
            self.scan_status = ScanStatus.GETTING_VAR
            return

        # Reset status back to SCANNING after attribute is accessed.
        self.scan_status = ScanStatus.SCANNING
        if not self.top_of_stack:
            return
        target_obj = self.get_tracked_local(self.top_of_stack)
        try:
            target_state = assert_base_state(target_obj, local_name=self.top_of_stack)

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Access the specific sub-state via typed attributes or get_state(SomeState) instead of arbitrary/dynamic access
  2. Declare dependencies explicitly with deps=[...] so the var is not auto-scanned
  3. Remove use of the forbidden attribute from the cached var body
Defensive patterns

Strategy: fallback

Try / catch

from reflex.vars.base import VarValueError
try:
    @rx.memo
    def v(self): return self._dynamic_access()
except VarValueError:
    @rx.memo(deps=[State.target])
    def v(self): return State.target.value

Prevention

When it happens

Trigger: Inside a cached computed var, calling something like self._get_state, or an attribute whose name is in the tracker's INVALID_NAMES set (internal/arbitrary state access helpers), triggering load_attr_or_method.

Common situations: Using private/internal state APIs or dynamic state access inside a @rx.memo var, which defeats dependency tracking.

Related errors


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