Răsfoiți Sursa

fix state reset() (#1501)

Thomas Brandého 1 an în urmă
părinte
comite
9222bbbdf2
2 a modificat fișierele cu 18 adăugiri și 6 ștergeri
  1. 0 3
      reflex/state.py
  2. 18 3
      tests/test_state.py

+ 0 - 3
reflex/state.py

@@ -632,9 +632,6 @@ class State(Base, ABC, extra=pydantic.Extra.allow):
         for substate in self.substates.values():
             substate.reset()
 
-        # Clean the state.
-        self.clean()
-
     def get_substate(self, path: Sequence[str]) -> Optional[State]:
         """Get the substate.
 

+ 18 - 3
tests/test_state.py

@@ -560,12 +560,27 @@ def test_reset(test_state, child_state):
     assert test_state.num2 == 3.14
     assert child_state.value == ""
 
+    expected_dirty_vars = {
+        "num1",
+        "num2",
+        "obj",
+        "upper",
+        "complex",
+        "is_hydrated",
+        "fig",
+        "key",
+        "sum",
+        "array",
+        "map_key",
+        "mapping",
+    }
+
     # The dirty vars should be reset.
-    assert test_state.dirty_vars == set()
-    assert child_state.dirty_vars == set()
+    assert test_state.dirty_vars == expected_dirty_vars
+    assert child_state.dirty_vars == {"count", "value"}
 
     # The dirty substates should be reset.
-    assert test_state.dirty_substates == set()
+    assert test_state.dirty_substates == {"child_state", "child_state2"}
 
 
 @pytest.mark.asyncio