remove dictify from state dict (#4141)

This commit is contained in:
Khaleel Al-Adhami 2024-10-10 12:18:18 -07:00 committed by GitHub
parent 87648af3ee
commit 8ec3cf6157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View File

@ -1879,13 +1879,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
self.dirty_vars.update(self._always_dirty_computed_vars)
self._mark_dirty()
def dictify(value: Any):
if dataclasses.is_dataclass(value) and not isinstance(value, type):
return dataclasses.asdict(value)
return value
base_vars = {
prop_name: dictify(self.get_value(getattr(self, prop_name)))
prop_name: self.get_value(getattr(self, prop_name))
for prop_name in self.base_vars
}
if initial and include_computed:

View File

@ -1290,19 +1290,19 @@ def test_computed_var_depends_on_parent_non_cached():
assert ps.dirty_vars == set()
assert cs.dirty_vars == set()
dict1 = ps.dict()
dict1 = json.loads(json_dumps(ps.dict()))
assert dict1[ps.get_full_name()] == {
"no_cache_v": 1,
"router": formatted_router,
}
assert dict1[cs.get_full_name()] == {"dep_v": 2}
dict2 = ps.dict()
dict2 = json.loads(json_dumps(ps.dict()))
assert dict2[ps.get_full_name()] == {
"no_cache_v": 3,
"router": formatted_router,
}
assert dict2[cs.get_full_name()] == {"dep_v": 4}
dict3 = ps.dict()
dict3 = json.loads(json_dumps(ps.dict()))
assert dict3[ps.get_full_name()] == {
"no_cache_v": 5,
"router": formatted_router,