|
9 | 9 | from abc import ABC, abstractmethod |
10 | 10 | from collections.abc import AsyncIterator, Callable, Coroutine |
11 | 11 | from types import MappingProxyType |
12 | | -from typing import TYPE_CHECKING, Any, ClassVar |
| 12 | +from typing import TYPE_CHECKING, ClassVar |
13 | 13 |
|
14 | 14 | from reflex.istate.manager.redis import StateManagerRedis |
15 | 15 | from reflex.state import BaseState, StateUpdate |
16 | 16 | from reflex.utils import console, prerequisites |
| 17 | +from reflex.utils.format import json_dumps |
17 | 18 | from reflex.utils.tasks import ensure_task |
18 | 19 |
|
19 | 20 | if TYPE_CHECKING: |
@@ -42,7 +43,7 @@ class LostAndFoundRecord: |
42 | 43 | """Record for a StateUpdate for a token with its socket on another instance.""" |
43 | 44 |
|
44 | 45 | token: str |
45 | | - update: dict[str, Any] |
| 46 | + update: StateUpdate |
46 | 47 |
|
47 | 48 |
|
48 | 49 | class TokenManager(ABC): |
@@ -386,8 +387,12 @@ async def _subscribe_lost_and_found_updates( |
386 | 387 | ) |
387 | 388 | async for message in pubsub.listen(): |
388 | 389 | if message["type"] == "pmessage": |
389 | | - record = LostAndFoundRecord(**json.loads(message["data"].decode())) |
390 | | - await emit_update(StateUpdate(**record.update), record.token) |
| 390 | + record_dict = json.loads(message["data"].decode()) |
| 391 | + record = LostAndFoundRecord( |
| 392 | + token=record_dict["token"], |
| 393 | + update=StateUpdate(**record_dict["update"]), |
| 394 | + ) |
| 395 | + await emit_update(record.update, record.token) |
391 | 396 |
|
392 | 397 | def ensure_lost_and_found_task( |
393 | 398 | self, |
@@ -454,11 +459,11 @@ async def emit_lost_and_found( |
454 | 459 | owner_instance_id = await self._get_token_owner(token) |
455 | 460 | if owner_instance_id is None: |
456 | 461 | return False |
457 | | - record = LostAndFoundRecord(token=token, update=dataclasses.asdict(update)) |
| 462 | + record = LostAndFoundRecord(token=token, update=update) |
458 | 463 | try: |
459 | 464 | await self.redis.publish( |
460 | 465 | f"channel:{self._get_lost_and_found_key(owner_instance_id)}", |
461 | | - json.dumps(dataclasses.asdict(record)), |
| 466 | + json_dumps(record), |
462 | 467 | ) |
463 | 468 | except Exception as e: |
464 | 469 | console.error(f"Redis error publishing lost and found delta: {e}") |
|
0 commit comments