|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from taskiq import InMemoryBroker |
| 4 | +from taskiq.kicker import AsyncKicker |
| 5 | + |
| 6 | + |
| 7 | +async def test_types_of_exceptions_not_serialized() -> None: |
| 8 | + """`types_of_exceptions` label should never be sent over the wire.""" |
| 9 | + broker = InMemoryBroker() |
| 10 | + |
| 11 | + @broker.task(types_of_exceptions=(ValueError, TypeError)) |
| 12 | + async def run_task() -> None: |
| 13 | + pass |
| 14 | + |
| 15 | + kicker = run_task.kicker() |
| 16 | + message = kicker._prepare_message() |
| 17 | + |
| 18 | + assert "types_of_exceptions" not in message.labels |
| 19 | + assert "types_of_exceptions" not in (message.labels_types or {}) |
| 20 | + |
| 21 | + |
| 22 | +async def test_types_of_exceptions_still_local_on_task() -> None: |
| 23 | + """The registered task still keeps the real exception types locally.""" |
| 24 | + broker = InMemoryBroker() |
| 25 | + |
| 26 | + @broker.task(types_of_exceptions=(ValueError, TypeError)) |
| 27 | + async def run_task() -> None: |
| 28 | + pass |
| 29 | + |
| 30 | + task = broker.find_task(run_task.task_name) |
| 31 | + assert task is not None |
| 32 | + assert task.labels["types_of_exceptions"] == (ValueError, TypeError) |
| 33 | + |
| 34 | + |
| 35 | +async def test_other_labels_still_serialized() -> None: |
| 36 | + """Unrelated labels are unaffected by the fix.""" |
| 37 | + kicker: AsyncKicker[Any, Any] = AsyncKicker( |
| 38 | + task_name="some_task", |
| 39 | + broker=InMemoryBroker(), |
| 40 | + labels={"retries": 3, "queue": "high_priority"}, |
| 41 | + ) |
| 42 | + message = kicker._prepare_message() |
| 43 | + |
| 44 | + assert message.labels["retries"] == "3" |
| 45 | + assert message.labels["queue"] == "high_priority" |
0 commit comments