Skip to content

Commit

Permalink
Disk state manager don't use byref (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo authored Sep 3, 2024
1 parent c07a983 commit 15a9f0a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,20 @@ def _default_token_expiration() -> int:
return get_config().redis_token_expiration


def _serialize_type(type_: Any) -> str:
"""Serialize a type.
Args:
type_: The type to serialize.
Returns:
The serialized type.
"""
if not inspect.isclass(type_):
return f"{type_}"
return f"{type_.__module__}.{type_.__qualname__}"


def state_to_schema(
state: BaseState,
) -> List[
Expand All @@ -2480,7 +2494,7 @@ def state_to_schema(
(
field_name,
model_field.name,
model_field.type_,
_serialize_type(model_field.type_),
(
model_field.required
if isinstance(model_field.required, bool)
Expand Down Expand Up @@ -2643,7 +2657,7 @@ async def set_state_for_substate(self, client_token: str, substate: BaseState):

self.states[substate_token] = substate

state_dilled = dill.dumps((state_to_schema(substate), substate), byref=True)
state_dilled = dill.dumps((state_to_schema(substate), substate))
if not self.states_directory.exists():
self.states_directory.mkdir(parents=True, exist_ok=True)
self.token_path(substate_token).write_bytes(state_dilled)
Expand Down

0 comments on commit 15a9f0a

Please sign in to comment.