Skip to content

Commit

Permalink
Suppress StateSchemaMismatchError and create a new state instance.
Browse files Browse the repository at this point in the history
If the serialized state's schema does not match the current corresponding state
schema, then we have to create a new instance.
  • Loading branch information
masenf committed Oct 7, 2024
1 parent 42f8fcf commit 4cec2d1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2979,15 +2979,18 @@ async def get_state(
"StateManagerRedis requires token to be specified in the form of {token}_{state_full_name}"
)

# The deserialized or newly created (sub)state instance.
state = None

# Fetch the serialized substate from redis.
redis_state = await self.redis.get(token)

if redis_state is not None:
# Deserialize the substate.
state = BaseState._deserialize(data=redis_state)
else:
# Key didn't exist so we have to create a new instance for this token.
# Instantiate the new state class (but don't persist it yet).
with contextlib.suppress(StateSchemaMismatchError):
state = BaseState._deserialize(data=redis_state)
if state is None:
# Key didn't exist or schema mismatch so create a new instance for this token.
state = state_cls(
init_substates=False,
_reflex_internal_init=True,
Expand Down

0 comments on commit 4cec2d1

Please sign in to comment.