|
@@ -29,6 +29,7 @@ from reflex.state import (
|
|
StateUpdate,
|
|
StateUpdate,
|
|
)
|
|
)
|
|
from reflex.utils import prerequisites
|
|
from reflex.utils import prerequisites
|
|
|
|
+from reflex.utils.format import json_dumps
|
|
from reflex.vars import BaseVar, ComputedVar
|
|
from reflex.vars import BaseVar, ComputedVar
|
|
|
|
|
|
from .states import GenState
|
|
from .states import GenState
|
|
@@ -2091,6 +2092,24 @@ def test_duplicate_substate_class(duplicate_substate):
|
|
duplicate_substate()
|
|
duplicate_substate()
|
|
|
|
|
|
|
|
|
|
|
|
+class Foo(Base):
|
|
|
|
+ """A class containing a list of str."""
|
|
|
|
+
|
|
|
|
+ tags: List[str] = ["123", "456"]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_json_dumps_with_mutables():
|
|
|
|
+ """Test that json.dumps works with Base vars inside mutable types."""
|
|
|
|
+
|
|
|
|
+ class MutableContainsBase(State):
|
|
|
|
+ items: List[Foo] = [Foo()]
|
|
|
|
+
|
|
|
|
+ dict_val = MutableContainsBase().dict()
|
|
|
|
+ assert isinstance(dict_val["items"][0], dict)
|
|
|
|
+ val = json_dumps(dict_val)
|
|
|
|
+ assert val == '{"is_hydrated": false, "items": [{"tags": ["123", "456"]}]}'
|
|
|
|
+
|
|
|
|
+
|
|
def test_reset_with_mutables():
|
|
def test_reset_with_mutables():
|
|
"""Calling reset should always reset fields to a copy of the defaults."""
|
|
"""Calling reset should always reset fields to a copy of the defaults."""
|
|
default = [[0, 0], [0, 1], [1, 1]]
|
|
default = [[0, 0], [0, 1], [1, 1]]
|