Skip to content

Commit 0b92c58

Browse files
Harsh Thakareharsh21234i
authored andcommitted
Handle non-scalar computed cache snapshots
1 parent 1ada24d commit 0b92c58

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎reflex/istate/shared.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from collections.abc import AsyncIterator
77
from dataclasses import MISSING
8-
from typing import TYPE_CHECKING, TypeVar
8+
from typing import Any, TYPE_CHECKING, TypeVar
99

1010
from reflex_base.constants import ROUTER_DATA, ROUTER_VARS
1111
from reflex_base.event import Event, get_hydrate_event
@@ -125,7 +125,7 @@ async def _patch_state(
125125
set[str],
126126
set[str],
127127
set[str],
128-
dict[str, tuple[bool, object, bool, object]],
128+
dict[str, tuple[bool, Any, bool, Any]],
129129
bool,
130130
]
131131
] = []
@@ -167,7 +167,7 @@ async def _patch_state(
167167
set[str],
168168
set[str],
169169
set[str],
170-
dict[str, tuple[bool, object, bool, object]],
170+
dict[str, tuple[bool, Any, bool, Any]],
171171
]
172172
] = []
173173
if not full_delta:
@@ -246,10 +246,13 @@ async def _patch_state(
246246
computed_vars_refreshed.update(
247247
name
248248
for name, computed_var in state.computed_vars.items()
249-
if computed_var_snapshots[name]
249+
if (
250+
computed_var_snapshots[name][0],
251+
computed_var_snapshots[name][2],
252+
computed_var_snapshots[name][3],
253+
)
250254
!= (
251255
hasattr(state, computed_var._cache_attr),
252-
getattr(state, computed_var._cache_attr, None),
253256
hasattr(state, computed_var._last_updated_attr),
254257
getattr(state, computed_var._last_updated_attr, None),
255258
)

‎tests/units/test_state.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ async def test_linked_state_patch_restores_computed_cache_on_resolve_error():
11691169

11701170
async def resolve_then_fail():
11711171
linked_state._mark_dirty()
1172+
linked_state._was_touched = True
11721173
await resolve_delta()
11731174
msg = "computed refresh failed"
11741175
raise RuntimeError(msg)

0 commit comments

Comments
 (0)