From d156aadfd6ee574a31a0ec1e11bee4b3d27aabfc Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Fri, 17 Apr 2026 15:18:27 +0200 Subject: [PATCH 1/2] Fixed shared labels. --- taskiq/decor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/taskiq/decor.py b/taskiq/decor.py index 44c624ef..8f90541c 100644 --- a/taskiq/decor.py +++ b/taskiq/decor.py @@ -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 ( @@ -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, ) From 5450e9d3a61a0cf3cccddfba08f5456deefcea72 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Fri, 17 Apr 2026 15:29:33 +0200 Subject: [PATCH 2/2] Added tests. --- tests/abc/test_broker.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/abc/test_broker.py b/tests/abc/test_broker.py index 889332e8..5c536cfb 100644 --- a/tests/abc/test_broker.py +++ b/tests/abc/test_broker.py @@ -1,4 +1,5 @@ from collections.abc import AsyncGenerator +from copy import copy from taskiq.abc.broker import AsyncBroker from taskiq.decor import AsyncTaskiqDecoratedTask @@ -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