Change task_id when calling function using Taskflow API

I’m calling the same function (Taskflow API python operator) multiples times and I’d like to give it a different task_id every time I call it (really my goal is to change the name of the task when displayed in the UI).

Example code:

def say_hi(name):
print(‘Hi’, name)

alex = say_hi(‘alex’)
bob = say_hi(‘bob’)

alex >> bob

I’d like to be able to rename the tasks to give it a more meaningful name. Currently these tasks would be displayed as say_hi and say_hi__1

Thanks for your time

Hi @jj_fin!

Since decorators are just syntax sugar around function calls you can try something like the snippet below. Assuming you’re not looping over some values of course.

from airflow.decorators import task

def say_hi(name):
    print("Hi", name)

alex = task(task_id="alex")(say_hi)(name="alex")
bob = task(task_id="bob")(say_hi)(name="bob")

alex >> bob