Consolidate logic in StateManagerRedis.get_state
This commit is contained in:
parent
6dba120e6d
commit
42f8fcf8e9
@ -2985,7 +2985,13 @@ class StateManagerRedis(StateManager):
|
|||||||
if redis_state is not None:
|
if redis_state is not None:
|
||||||
# Deserialize the substate.
|
# Deserialize the substate.
|
||||||
state = BaseState._deserialize(data=redis_state)
|
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).
|
||||||
|
state = state_cls(
|
||||||
|
init_substates=False,
|
||||||
|
_reflex_internal_init=True,
|
||||||
|
)
|
||||||
# Populate parent state if missing and requested.
|
# Populate parent state if missing and requested.
|
||||||
if parent_state is None:
|
if parent_state is None:
|
||||||
parent_state = await self._get_parent_state(token, state)
|
parent_state = await self._get_parent_state(token, state)
|
||||||
@ -3008,28 +3014,6 @@ class StateManagerRedis(StateManager):
|
|||||||
return state._get_root_state()
|
return state._get_root_state()
|
||||||
return state
|
return state
|
||||||
|
|
||||||
# TODO: dedupe the following logic with the above block
|
|
||||||
# Key didn't exist so we have to create a new instance for this token.
|
|
||||||
if parent_state is None:
|
|
||||||
parent_state = await self._get_parent_state(token)
|
|
||||||
# Instantiate the new state class (but don't persist it yet).
|
|
||||||
state = state_cls(
|
|
||||||
parent_state=parent_state,
|
|
||||||
init_substates=False,
|
|
||||||
_reflex_internal_init=True,
|
|
||||||
)
|
|
||||||
# Set up Bidirectional linkage between this state and its parent.
|
|
||||||
if parent_state is not None:
|
|
||||||
parent_state.substates[state.get_name()] = state
|
|
||||||
state.parent_state = parent_state
|
|
||||||
# Populate substates for the newly created state.
|
|
||||||
await self._populate_substates(token, state, all_substates=get_substates)
|
|
||||||
# To retain compatibility with previous implementation, by default, we return
|
|
||||||
# the top-level state by chasing `parent_state` pointers up the tree.
|
|
||||||
if top_level:
|
|
||||||
return state._get_root_state()
|
|
||||||
return state
|
|
||||||
|
|
||||||
def _warn_if_too_large(
|
def _warn_if_too_large(
|
||||||
self,
|
self,
|
||||||
state: BaseState,
|
state: BaseState,
|
||||||
|
Loading…
Reference in New Issue
Block a user