Skip to content

Commit ef9083f

Browse files
claudemasenf
authored andcommitted
test(state): add regression test for get_var_value with async computed vars
Reproduces the bug fixed in #6391 where get_var_value returned the un-awaited coroutine for an async computed var instead of the underlying value. https://claude.ai/code/session_01PLGmhJG9HNUzobmBRXQUnc
1 parent 6903d40 commit ef9083f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/units/test_state.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,6 +4396,38 @@ async def test_get_var_value(
43964396
}
43974397

43984398

4399+
@pytest.mark.asyncio
4400+
async def test_get_var_value_async_computed_var(
4401+
token: str, attached_mock_event_context: EventContext
4402+
):
4403+
"""Test that get_var_value awaits async computed vars and returns their value.
4404+
4405+
Regression test for https://github.com/reflex-dev/reflex/pull/6391: previously
4406+
get_var_value returned the un-awaited coroutine for async computed vars rather
4407+
than the underlying value.
4408+
4409+
Args:
4410+
token: A token.
4411+
attached_mock_event_context: An event context that will be attached to the app's state manager.
4412+
"""
4413+
4414+
class StateWithAsyncCV(BaseState):
4415+
"""A state with an async computed var."""
4416+
4417+
base: int = 5
4418+
4419+
@rx.var(cache=True)
4420+
async def doubled(self) -> int:
4421+
return self.base * 2
4422+
4423+
state_manager = attached_mock_event_context.state_manager
4424+
state = await state_manager.get_state(
4425+
BaseStateToken(ident=token, cls=StateWithAsyncCV)
4426+
)
4427+
4428+
assert await state.get_var_value(StateWithAsyncCV.doubled) == 10
4429+
4430+
43994431
@pytest.mark.asyncio
44004432
async def test_async_computed_var_get_state(
44014433
token: str, attached_mock_event_context: EventContext

0 commit comments

Comments
 (0)