Skip to content

Commit

Permalink
fix: state size was not checked for dill (#4431)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-bartscher authored Nov 25, 2024
1 parent 697e26c commit d7d46e4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,11 +2175,9 @@ def _serialize(self) -> bytes:
Returns:
The serialized state.
"""
payload = b""
try:
pickle_state = pickle.dumps((self._to_schema(), self))
if environment.REFLEX_PERF_MODE.get() != PerformanceMode.OFF:
self._check_state_size(len(pickle_state))
return pickle_state
payload = pickle.dumps((self._to_schema(), self))
except HANDLED_PICKLE_ERRORS as og_pickle_error:
error = (
f"Failed to serialize state {self.get_full_name()} due to unpicklable object. "
Expand All @@ -2188,16 +2186,18 @@ def _serialize(self) -> bytes:
try:
import dill

return dill.dumps((self._to_schema(), self))
payload = dill.dumps((self._to_schema(), self))
except ImportError:
error += (
f"Pickle error: {og_pickle_error}. "
"Consider `pip install 'dill>=0.3.8'` for more exotic serialization support."
)
except HANDLED_PICKLE_ERRORS as ex:
error += f"Dill was also unable to pickle the state: {ex}"
console.warn(error)
return b""
console.warn(error)
if environment.REFLEX_PERF_MODE.get() != PerformanceMode.OFF:
self._check_state_size(len(payload))
return payload

@classmethod
def _deserialize(
Expand Down

0 comments on commit d7d46e4

Please sign in to comment.