https://prefect.io logo
Title
o

Oscar Björhn

08/11/2022, 1:50 PM
Is there currently a way of overriding a task name when calling it in Prefect 2? The following (which is what the documentation recommends, unless I'm reading it wrong) appears to have no effect: my_task_function(name="Custom Task Name") The task run name for the above task ends up being "my_task_function-6971d82e-1"
1
j

Jamie Blakeman

08/11/2022, 3:00 PM
The name part goes in the task decorator, eg
@task(name="Custom Task Name")
def my_task_function():
o

Oscar Björhn

08/11/2022, 3:07 PM
That's one way of doing it, but then I can't override it each time I execute the task, which is what I'm trying to accomplish. Unless you can override task decorators at runtime?
j

Jamie Blakeman

08/11/2022, 3:10 PM
oops, in which case:
my_task_function.with_options(name="Custom Task Name")
, worked for me
👍 1
o

Oscar Björhn

08/11/2022, 3:19 PM
Awesome, that works. Thanks! 🤩
k

Khuyen Tran

08/11/2022, 4:45 PM
not sure why you can’t see the change in the UI.
@task(name="Custom Task Name")
should change your task name into
Custom Task Name-id
o

Oscar Björhn

08/11/2022, 4:50 PM
I think I wasn't explaining my issue properly: I need to run the same task, multiple times, with different names. So I don't think the decorator override will do! with_options worked, even though it's a bit clumsy to use. So I'm all good now.
t

Timo

09/01/2022, 1:05 PM
Is there a way to template the task name based on the input like in v1.0 ? (especially for mapped tasks) https://docs-v1.prefect.io/core/concepts/templating.html
@Khuyen Tran just pinging you in case u missed my question 🙂
k

Khuyen Tran

09/06/2022, 3:05 PM
We currently don’t support it, but here is the work around
🙌 1
t

Timo

09/06/2022, 3:08 PM
thank you. this will work for me 🙂
@Khuyen Tran another question: the provided workaround doesn't work for mapped tasks, right? Is there another work around?
z

Zanie

09/09/2022, 3:41 PM
Feel free to open a GitHub feature request for dynamic templating of task run names — I do not believe there are workaround for mapping yet.
k

Khuyen Tran

09/09/2022, 7:52 PM
@Timo Can you open a GitHub issue on Prefect repo so we can keep track of the issue?