Skip to content

Shared schedule labels leak between tasks during discovery #702

Open

Description

@IlyaKhalafi

Taskiq version

Current master at f08a54a

Python version

Python 3.12

OS

Linux

What happened?

When two tasks reuse a schedule dictionary, discovering the first task adds its task-level labels to that dictionary. The second task then inherits those labels even when it does not declare them.

The example below gives default_task the queue="dedicated" label and changes the original schedule configuration. Each discovered schedule should have independent labels, and discovery should leave the input configuration unchanged.

Broker initialization code

import asyncio

from taskiq import InMemoryBroker
from taskiq.schedule_sources.label_based import LabelScheduleSource


async def main():
    schedule = {"cron": "* * * * *", "labels": {"origin": "nightly"}}
    broker = InMemoryBroker()

    @broker.task(task_name="dedicated_task", schedule=[schedule], queue="dedicated")
    async def dedicated():
        pass

    @broker.task(task_name="default_task", schedule=[schedule])
    async def default():
        pass

    source = LabelScheduleSource(broker)
    await source.startup()
    for entry in await source.get_schedules():
        print(entry.task_name, entry.labels)
    print("original_schedule_labels", schedule["labels"])
    await broker.shutdown()


asyncio.run(main())

Relevant log output

dedicated_task {'origin': 'nightly', 'queue': 'dedicated'}
default_task {'origin': 'nightly', 'queue': 'dedicated'}
original_schedule_labels {'origin': 'nightly', 'queue': 'dedicated'}

This concerns label discovery, rather than the kicker path in #301. The earlier recursive-label fix in #520 removes the schedule key from task labels but still updates the caller's label dictionary.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions