Skip to content

Commit 699f8c9

Browse files
authored
ENG-8388: refetch cached state when missing substates (#5991)
Avoid issue where hydrate operates on a subset of the tree because the Root state was requested, but it didn't have all its substates cached, so it doesn't return the full dict.
1 parent a987437 commit 699f8c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

reflex/istate/manager/redis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,12 @@ async def _get_state_cached(self, token: str) -> AsyncIterator[BaseState | None]
557557
) is not None:
558558
# Make sure we have the substate cached (or fetch it from redis).
559559
try:
560-
_ = cached_state.get_substate(state_path.split("."))
560+
substate = cached_state.get_substate(state_path.split("."))
561+
if len(substate.substates) != len(
562+
type(substate).get_substates()
563+
):
564+
# If the substate is missing substates, we need to refetch it.
565+
raise ValueError # noqa: TRY301
561566
except ValueError:
562567
await self.get_state(token, for_state_instance=cached_state)
563568
yield cached_state

0 commit comments

Comments
 (0)