{"record":{"id":"478bbc66d4b373db","repo":"reflex-dev/reflex","slug":"dependency-detection-cannot-identify-get-state-cla","errorCode":null,"errorMessage":"Dependency detection cannot identify get_state class from a code object.","messagePattern":"Dependency detection cannot identify get_state class from a code object\\.","errorType":"exception","errorClass":"VarValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/dep_tracking.py","lineNumber":265,"sourceCode":"    def handle_getting_state(self, instruction: dis.Instruction) -> None:\n        \"\"\"Handle bytecode analysis when `get_state` was called in the function.\n\n        If the wrapped function is getting an arbitrary state and saving it to a\n        local variable, this method associates the local variable name with the\n        state class in self.tracked_locals.\n\n        When an attribute/method is accessed on a tracked local, it will be\n        associated with this state.\n\n        Args:\n            instruction: The dis instruction to process.\n\n        Raises:\n            VarValueError: if the state class cannot be determined from the instruction.\n        \"\"\"\n        if isinstance(self.func, CodeType):\n            msg = \"Dependency detection cannot identify get_state class from a code object.\"\n            raise VarValueError(msg)\n        if instruction.opname in (\"LOAD_FAST\", \"LOAD_FAST_BORROW\"):\n            self._getting_state_class = self.get_tracked_local(\n                local_name=instruction.argval,\n            )\n        elif instruction.opname == \"LOAD_GLOBAL\":\n            # Special case: referencing state class from global scope.\n            try:\n                self._getting_state_class = self._get_globals()[instruction.argval]\n            except (ValueError, KeyError) as ve:\n                msg = f\"Cached var {self!s} cannot access arbitrary state `{instruction.argval}`, not found in globals.\"\n                raise VarValueError(msg) from ve\n        elif instruction.opname == \"LOAD_DEREF\":\n            # Special case: referencing state class from closure.\n            try:\n                self._getting_state_class = self._get_closure()[instruction.argval]\n            except (ValueError, KeyError) as ve:\n                msg = f\"Cached var {self!s} cannot access arbitrary state `{instruction.argval}`, is it defined yet?\"\n                raise VarValueError(msg) from ve","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/dep_tracking.py#L247-L283","documentation":"When a cached computed var calls get_state(SomeState), the tracker must resolve the state class from the instruction. If the tracked function is a raw code object (not a function with __globals__/closure), the class cannot be identified, so VarValueError is raised.","triggerScenarios":"Dependency scanning a function compiled from a bare code object (e.g. types.FunctionType built from a code object, or reconstructed/pickled functions) that calls self.get_state(...).","commonSituations":"Advanced usage passing code objects to ComputedVar; hot-reload/pickling edge cases that lose function metadata.","solutions":["Pass a real function (with globals and closure intact) to the computed var instead of a CodeType","Avoid get_state in code-object-based computed vars; declare deps explicitly"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import types\nassert not isinstance(func, types.CodeType), 'pass a real function, not a code object'","typeGuard":"def is_real_function(f) -> bool:\n    import types, inspect\n    return inspect.isfunction(f) and not isinstance(f, types.CodeType)","tryCatchPattern":null,"preventionTips":["Pass actual functions to ComputedVar, never raw code objects","Avoid get_state in reconstructed/pickled computed vars"],"tags":["reflex","dependency-tracking","code-object","internal"],"backgroundTag":"unresolvable-symbol-reference","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}