diff --git a/reflex/vars.py b/reflex/vars.py index 6d5c21fdd..7f0bbaa8e 100644 --- a/reflex/vars.py +++ b/reflex/vars.py @@ -2174,8 +2174,21 @@ class ComputedVar(Var, property): obj=ref_obj, ) ) - else: - # normal attribute access + # recurse into property fget functions + elif isinstance(ref_obj, property) and not isinstance( + ref_obj, ComputedVar + ): + d.update( + self._deps( + objclass=objclass, + obj=ref_obj.fget, # type: ignore + ) + ) + elif ( + instruction.argval in objclass.backend_vars + or instruction.argval in objclass.vars + ): + # var access d.add(instruction.argval) elif instruction.opname == "LOAD_CONST" and isinstance( instruction.argval, CodeType diff --git a/tests/test_state.py b/tests/test_state.py index b18fd259c..12e4f6100 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -1278,6 +1278,10 @@ def test_computed_var_dependencies(): y: List[int] = [1, 2, 3] _z: List[int] = [1, 2, 3] + @property + def testprop(self) -> int: + return self.v + @rx.var(cache=True) def comp_v(self) -> int: """Direct access. @@ -1287,6 +1291,15 @@ def test_computed_var_dependencies(): """ return self.v + @rx.var(cache=True) + def comp_v_via_property(self) -> int: + """Access v via property. + + Returns: + The value of v via property. + """ + return self.testprop + @rx.var(cache=True) def comp_w(self): """Nested lambda. @@ -1328,7 +1341,7 @@ def test_computed_var_dependencies(): return [z in self._z for z in range(5)] cs = ComputedState() - assert cs._computed_var_dependencies["v"] == {"comp_v"} + assert cs._computed_var_dependencies["v"] == {"comp_v", "comp_v_via_property"} assert cs._computed_var_dependencies["w"] == {"comp_w"} assert cs._computed_var_dependencies["x"] == {"comp_x"} assert cs._computed_var_dependencies["y"] == {"comp_y"}