diff --git a/reflex/state.py b/reflex/state.py index 0f0ba97f9..3ccddfc9b 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -2093,6 +2093,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): # Never serialize parent_state or substates. state["__dict__"].pop("parent_state", None) state["__dict__"].pop("substates", None) + state["__dict__"].pop("dirty_vars", None) + state["__dict__"].pop("dirty_substates", None) state["__dict__"].pop("_was_touched", None) # Remove all inherited vars. for inherited_var_name in self.inherited_vars: @@ -2109,6 +2111,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): """ state["__dict__"]["parent_state"] = None state["__dict__"]["substates"] = {} + state["__dict__"]["dirty_vars"] = set() + state["__dict__"]["dirty_substates"] = set() super().__setstate__(state) def _check_state_size( diff --git a/tests/units/test_state.py b/tests/units/test_state.py index fc4b5fe3b..22f1c9f0e 100644 --- a/tests/units/test_state.py +++ b/tests/units/test_state.py @@ -2581,10 +2581,7 @@ def test_mutable_copy(mutable_state: MutableTestState, copy_func: Callable): assert getattr(ms_copy, attr) is not getattr(mutable_state, attr) ms_copy.custom.array.append(42) assert "custom" in ms_copy.dirty_vars - if copy_func is copy.copy: - assert "custom" in mutable_state.dirty_vars - else: - assert not mutable_state.dirty_vars + assert not mutable_state.dirty_vars @pytest.mark.parametrize(