Hi there, can I run a async task like `prefect-dbt...
# prefect-community
t
Hi there, can I run a async task like
prefect-dbt
's
trigger_dbt_cli_command()
inside another task? This does not work for
async
tasks. Thanks
1
n
Hi @Timo, You cannot call a task within a task, whether sync or async. However you can always have a flow call the task, since with prefect 2 you're free to call a flow from inside a flow
Copy code
@flow
def my_dbt_flow():
   trigger_dbt_cli_command()

@flow
def parent_flow():
   my_dbt_flow()
I wouldn't recommend using
Task.fn
to retrieve the standard python callable from your task here, because even then you're not calling a task within a task, you're only calling a task's python function and so it won't behave like a prefect task
t
Thanks @Nate. I already doing this but I look forward to minimize the subflow calls....for a sync task its possible to call the underlying function with the
.fn()
call. But is this is not working for the async functions. Therefore I asked my question. Maybe to be more precise: Is it possible to call the underlying function of a async task?
n
i made a slight edit above to address that point generally speaking I wouldn't recommend using
.fn()
outside of testing scenarios because you lose all orchestration functionality that comes with prefect tasks, since you're no longer calling a prefect task (only the task's python function) that said it is technically possible to call
trigger_dbt_cli_command.fn()
from within a task, sync or async
t
sadly does not work for me
Copy code
RuntimeWarning: coroutine 'trigger_dbt_cli_command' was never awaited
  trigger_dbt_cli_command.fn(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
n
it looks like you didn't await the coroutine
t
ok....have to make my task
async
aswell then it works. thank you
👍 1