Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion taskiq/decor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from collections.abc import Callable, Coroutine
from copy import copy
from datetime import datetime, timedelta
from types import CoroutineType
from typing import (
Expand Down Expand Up @@ -225,7 +226,7 @@ def kicker(self) -> AsyncKicker[_FuncParams, _ReturnType]:
return AsyncKicker(
task_name=self.task_name,
broker=self.broker,
labels=self.labels,
labels=copy(self.labels),
return_type=self.return_type,
)

Expand Down
15 changes: 15 additions & 0 deletions tests/abc/test_broker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import AsyncGenerator
from copy import copy

from taskiq.abc.broker import AsyncBroker
from taskiq.decor import AsyncTaskiqDecoratedTask
Expand Down Expand Up @@ -61,3 +62,17 @@ async def test_func() -> None:
"label1": 1,
"label2": 2,
}


def test_kicker_labels_modification() -> None:
"""Test that using kicker.with_labels doesn't modify task's labels globally."""
broker = _TestBroker()

@broker.task(test_lb="one")
async def test_task() -> None: ...

old_labels = copy(test_task.labels)
test_kicker = test_task.kicker().with_labels(another_label="test")
assert "another_label" in test_kicker.labels

assert test_task.labels == old_labels
Loading