Peter Žáčik
11/18/2025, 7:51 AM@task(name="load", task_run_name="load-{target_date}", tags=["{target}-load"])Marvin
11/18/2025, 7:51 AMMarvin
11/18/2025, 7:55 AMtask_run_name supports dynamic formatting with parameters, but tags on the @task decorator are static. A literal tags=["{target}-load"] will stay exactly that string.
Supported ways to add dynamic tags:
- Use the prefect.tags(...) context manager around the call site
- Use task.with_options(tags=[...]) at call time
Examples:
from prefect import task, flow, tags
@task(name="load", task_run_name="load-{target_date}", tags={"static"})
def load(target: str, target_date: str):
...
@flow
def etl(target: str, target_date: str):
# 1) Context manager — tags are added to all task runs inside this block
with tags(f"{target}-load"):
load(target=target, target_date=target_date)
# 2) with_options at call-time — creates a modified copy of the task
load.with_options(tags=[f"{target}-load"])(target=target, target_date=target_date)
Notes:
- Tags from the decorator and from prefect.tags(...) are combined.
- task_run_name="load-{target_date}" will format using the task’s parameters.
Refs:
- Task decorator API (incl. tags and task_run_name): Task API
- Tags context manager source/docs: prefect.context.tags
- Task class with_options (supports tags at call time): prefect.tasks.Task
- How-to: tag-based concurrency limits: Tag-based concurrency