Skip to content

Commit

Permalink
fix: every computed var should get it's own static deps (#4914)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-bartscher authored Mar 7, 2025
1 parent 3640b39 commit b868bc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion reflex/vars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import contextlib
import copy
import dataclasses
import datetime
import functools
Expand Down Expand Up @@ -2146,7 +2147,7 @@ def _replace(
"fget": kwargs.pop("fget", self._fget),
"initial_value": kwargs.pop("initial_value", self._initial_value),
"cache": kwargs.pop("cache", self._cache),
"deps": kwargs.pop("deps", self._static_deps),
"deps": kwargs.pop("deps", copy.copy(self._static_deps)),
"auto_deps": kwargs.pop("auto_deps", self._auto_deps),
"interval": kwargs.pop("interval", self._update_interval),
"backend": kwargs.pop("backend", self._backend),
Expand Down
19 changes: 19 additions & 0 deletions tests/units/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3916,3 +3916,22 @@ class OtherState(rx.State):

other_state.data.append({"foo": "baz"})
assert "rows" in comp_state.dirty_vars


def test_computed_var_mutability() -> None:
class CvMixin(rx.State, mixin=True):
@rx.var(cache=True, deps=["hi"])
def cv(self) -> int:
return 42

class FirstCvState(CvMixin, rx.State):
pass

class SecondCvState(CvMixin, rx.State):
pass

first_cv = FirstCvState.computed_vars["cv"]
second_cv = SecondCvState.computed_vars["cv"]

assert first_cv is not second_cv
assert first_cv._static_deps is not second_cv._static_deps

0 comments on commit b868bc7

Please sign in to comment.