From e2583c48c978e16af25cd895c4285b3bc2dce710 Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Sat, 7 Dec 2024 13:36:15 +0100 Subject: [PATCH] minor pickle improvement --- reflex/state.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/reflex/state.py b/reflex/state.py index 55f29cf45..0eec1e2c9 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -2105,14 +2105,26 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): 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,