MCPcopy
hub / github.com/reflex-dev/reflex / _resolve_linked_state

Method _resolve_linked_state

reflex/istate/shared.py:179–209  ·  view source on GitHub ↗

Load and patch a linked state that was not pre-loaded in the tree. Called by State._get_state_from_redis when a state in _reflex_internal_links is not yet in the cache. This loads the private copy into the tree first, then patches the linked version on top of it via

(
        self, state_cls: type["BaseState"], linked_token: str
    )

Source from the content-addressed store, hash-verified

177 ]
178
179 async def _resolve_linked_state(
180 self, state_cls: type["BaseState"], linked_token: str
181 ) -> "BaseState":
182 """Load and patch a linked state that was not pre-loaded in the tree.
183
184 Called by State._get_state_from_redis when a state in
185 _reflex_internal_links is not yet in the cache. This loads the
186 private copy into the tree first, then patches the linked version
187 on top of it via _internal_patch_linked_state.
188
189 Args:
190 state_cls: The shared state class to resolve.
191 linked_token: The shared token the state is linked to.
192
193 Returns:
194 The linked state instance, patched into the current tree.
195
196 Raises:
197 ReflexRuntimeError: If the resolved state is not a SharedState.
198 """
199 root_state = self._get_root_state()
200
201 # Load the private copy into the tree so _internal_patch_linked_state
202 # has an original to swap out (needed for unlink / restore).
203 original_state = await BaseState._get_state_from_redis(root_state, state_cls)
204
205 if isinstance(original_state, SharedStateBaseInternal):
206 return await original_state._internal_patch_linked_state(linked_token)
207
208 msg = f"Failed to resolve linked state {state_cls.get_full_name()} for token {linked_token}: state does not inherit from rx.SharedState"
209 raise ReflexRuntimeError(msg)
210
211 async def _link_to(self, token: str) -> Self:
212 """Link this shared state to a token.

Callers 1

_get_state_from_redisMethod · 0.80

Calls 5

ReflexRuntimeErrorClass · 0.90
_get_root_stateMethod · 0.80
get_full_nameMethod · 0.80
_get_state_from_redisMethod · 0.45

Tested by

no test coverage detected