Skip to content

Commit

Permalink
minor pickle improvement (#4499)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-bartscher authored Dec 12, 2024
1 parent 5e026e4 commit ea90a3e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2122,14 +2122,26 @@ def __getstate__(self):
state["__dict__"].pop("router", None)
state["__dict__"].pop("router_data", None)
# Never serialize parent_state or substates.
state["__dict__"]["parent_state"] = None
state["__dict__"]["substates"] = {}
state["__dict__"].pop("parent_state", None)
state["__dict__"].pop("substates", None)
state["__dict__"].pop("_was_touched", None)
# Remove all inherited vars.
for inherited_var_name in self.inherited_vars:
state["__dict__"].pop(inherited_var_name, None)
return state

def __setstate__(self, state: dict[str, Any]):
"""Set the state from redis deserialization.
This method is called by pickle to deserialize the object.
Args:
state: The state dict for deserialization.
"""
state["__dict__"]["parent_state"] = None
state["__dict__"]["substates"] = {}
super().__setstate__(state)

def _check_state_size(
self,
pickle_state_size: int,
Expand Down

0 comments on commit ea90a3e

Please sign in to comment.