|
77 | 77 | from reflex.event import ( |
78 | 78 | _EVENT_FIELDS, |
79 | 79 | Event, |
80 | | - EventHandler, |
81 | 80 | EventSpec, |
82 | 81 | EventType, |
83 | 82 | IndividualEventType, |
84 | 83 | get_hydrate_event, |
85 | 84 | noop, |
86 | 85 | ) |
| 86 | +from reflex.istate.proxy import StateProxy |
87 | 87 | from reflex.page import DECORATED_PAGES |
88 | 88 | from reflex.route import ( |
89 | 89 | get_route_args, |
@@ -1619,6 +1619,8 @@ def _process_background( |
1619 | 1619 | if not handler.is_background: |
1620 | 1620 | return None |
1621 | 1621 |
|
| 1622 | + substate = StateProxy(substate) |
| 1623 | + |
1622 | 1624 | async def _coro(): |
1623 | 1625 | """Coroutine to process the event and emit updates inside an asyncio.Task. |
1624 | 1626 |
|
@@ -1934,21 +1936,14 @@ async def upload_file(request: Request): |
1934 | 1936 | substate_token = _substate_key(token, handler.rpartition(".")[0]) |
1935 | 1937 | state = await app.state_manager.get_state(substate_token) |
1936 | 1938 |
|
1937 | | - # get the current session ID |
1938 | | - # get the current state(parent state/substate) |
1939 | | - path = handler.split(".")[:-1] |
1940 | | - current_state = state.get_substate(path) |
1941 | 1939 | handler_upload_param = () |
1942 | 1940 |
|
1943 | | - # get handler function |
1944 | | - func = getattr(type(current_state), handler.split(".")[-1]) |
| 1941 | + _current_state, event_handler = state._get_event_handler(handler) |
1945 | 1942 |
|
1946 | | - # check if there exists any handler args with annotation, list[UploadFile] |
1947 | | - if isinstance(func, EventHandler): |
1948 | | - if func.is_background: |
1949 | | - msg = f"@rx.event(background=True) is not supported for upload handler `{handler}`." |
1950 | | - raise UploadTypeError(msg) |
1951 | | - func = func.fn |
| 1943 | + if event_handler.is_background: |
| 1944 | + msg = f"@rx.event(background=True) is not supported for upload handler `{handler}`." |
| 1945 | + raise UploadTypeError(msg) |
| 1946 | + func = event_handler.fn |
1952 | 1947 | if isinstance(func, functools.partial): |
1953 | 1948 | func = func.func |
1954 | 1949 | for k, v in get_type_hints(func).items(): |
|
0 commit comments