{"record":{"id":"e521ffd94f031ce8","repo":"reflex-dev/reflex","slug":"local-name-r-is-not-tracked-in-the-current-scope","errorCode":null,"errorMessage":"{local_name!r} is not tracked in the current scope.","messagePattern":"(.+?) is not tracked in the current scope\\.","errorType":"exception","errorClass":"UntrackedLocalVarError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/dep_tracking.py","lineNumber":146,"sourceCode":"\n    def get_tracked_local(self, local_name: str) -> type[BaseState] | ModuleType:\n        \"\"\"Get the value of a local name tracked in the current function scope.\n\n        Args:\n            local_name: The name of the local variable to fetch.\n\n        Returns:\n            The value of local name tracked in the current scope (a referenced\n            BaseState subclass or imported module).\n\n        Raises:\n            UntrackedLocalVarError: If the local variable is not being tracked.\n        \"\"\"\n        try:\n            local_value = self.tracked_locals[local_name]\n        except KeyError as ke:\n            msg = f\"{local_name!r} is not tracked in the current scope.\"\n            raise UntrackedLocalVarError(msg) from ke\n        return local_value\n\n    def load_attr_or_method(self, instruction: dis.Instruction) -> None:\n        \"\"\"Handle loading an attribute or method from the object on top of the stack.\n\n        This method directly tracks attributes and recursively merges\n        dependencies from analyzing the dependencies of any methods called.\n\n        Args:\n            instruction: The dis instruction to process.\n\n        Raises:\n            VarValueError: if the attribute is an disallowed name or attribute\n                does not reference a BaseState.\n        \"\"\"\n        from .base import ComputedVar\n\n        if instruction.argval in self.INVALID_NAMES:","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/dep_tracking.py#L128-L164","documentation":"The dependency tracker walks bytecode and only understands locals it has recorded (function args, assignments, comprehensions). Accessing a local name it never tracked raises UntrackedLocalVarError.","triggerScenarios":"A cached computed var that references a closure variable, imported symbol used as a local, or an exotic bytecode pattern the tracker does not model, then calls get_tracked_local for that name.","commonSituations":"Cached computed vars using complex helpers, lambdas, walrus edge cases, or language features newer than the tracker supports.","solutions":["Simplify the computed var: reference state attributes directly (self.other.value) so tracking works","Move complex logic into a plain (non-cached, non-tracked) helper and pass explicit values","Explicitly declare deps=[...] so automatic tracking is not required","Report the pattern upstream if it looks like valid code the tracker should support"],"exampleFix":"# before\n@rx.memo\ndef full(self):\n    name = format_name(self.first, self.last)  # helper confuses tracker\n    return name\n# after\n@rx.memo\ndef full(self):\n    return f\"{self.first} {self.last}\"","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"from reflex.vars.dep_tracking import UntrackedLocalVarError\ntry:\n    @rx.memo\n    def v(self): return complex_helper(self.a, self.b)\nexcept UntrackedLocalVarError:\n    @rx.memo(deps=[State.a, State.b])\n    def v(self): return complex_helper(self.a, self.b)","preventionTips":["Keep cached computed vars simple: direct self.attr references","Declare deps explicitly when logic is complex","Avoid closures/walrus/exotic patterns inside tracked functions"],"tags":["reflex","dependency-tracking","computed-var","bytecode"],"backgroundTag":"dependency-resolution-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}