What would be the correct syntax to naming my task...
# ask-community
m
What would be the correct syntax to naming my tasks? The
name=""
suggested in the documentation isn't working for the format I have my tasks in
Copy code
campaign_details_dbt_run = dbt_task(name="Campaign Details", command='dbt run -m campaign_details')
and
dbt_task = DbtShellTask())
k
The name should go in the init so
dbt_task = DbtShellTask(name="...")
m
there's no way to name the other tasks? Because I use the same DbtShellTask() for different commands that I want to name
k
You can template the
task run name
based on inputs like this ? But for the actual task name, I don’t think so. You could have DbtShellTask in your flow code like this:
Copy code
with Flow(...) as flow:
    a = DbtShellTask(name=...)(cmd=...)
    b = DbtShellTask(name=...)(cmd=...)
m
hmm but I don't want to have to keep reusing DbtShellTask since it has a my kwargs and some other info that would be repetitive
I just need it so each of these tasks has their own name rather than the tasl name
k
You can do
Copy code
a = DbtShellTask(all_the_kwargs)
b = a
b.name = xxx
c = a
c.name = xxx

with Flow(...) as flow:
    a = DbtShellTask(name=...)(cmd=...)
    b = DbtShellTask(name=...)(cmd=...)
or maybe
Copy code
dict_of_kwargs = {...}
a = DbtShellTask(**dict_of_kwargs)
dict_of_kwargs['name'] = xxx
b = DbtShellTask(**dict_of_kwargs)

with Flow(...) as flow:
    a = a(cmd=...)
    b = b(cmd=...)
c
Another option here is:
Copy code
campaign_details_dbt_run = dbt_task(task_args={"name": "Campaign Details"}, command='dbt run -m campaign_details')
the special keyword
task_args
allows you to override init kwargs (which includes
name
) when you call the task
👍 1
m
cool, thanks!