Skip to content

Commit c923a97

Browse files
authored
make _no_chain_background_task take state instance (#5857)
1 parent cf6e3a6 commit c923a97

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

reflex/state.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@
9494
VAR_TYPE = TypeVar("VAR_TYPE")
9595

9696

97-
def _no_chain_background_task(
98-
state_cls: type[BaseState], name: str, fn: Callable
99-
) -> Callable:
97+
def _no_chain_background_task(state: BaseState, name: str, fn: Callable) -> Callable:
10098
"""Protect against directly chaining a background task from another event handler.
10199
102100
Args:
103-
state_cls: The state class that the event handler is in.
101+
state: The state instance the background task is bound to.
104102
name: The name of the background task.
105103
fn: The background task coroutine function / generator.
106104
@@ -110,7 +108,7 @@ def _no_chain_background_task(
110108
Raises:
111109
TypeError: If the background task is not async.
112110
"""
113-
call = f"{state_cls.__name__}.{name}"
111+
call = f"{type(state).__name__}.{name}"
114112
message = (
115113
f"Cannot directly call background task {name!r}, use "
116114
f"`yield {call}` or `return {call}` instead."
@@ -1349,7 +1347,7 @@ def __getattribute__(self, name: str) -> Any:
13491347
if name in event_handlers:
13501348
handler = event_handlers[name]
13511349
if handler.is_background:
1352-
fn = _no_chain_background_task(type(self), name, handler.fn)
1350+
fn = _no_chain_background_task(self, name, handler.fn)
13531351
else:
13541352
fn = functools.partial(handler.fn, self)
13551353
fn.__module__ = handler.fn.__module__

0 commit comments

Comments
 (0)