Does anyone know of a workaround to run a task fro...
# prefect-community
Does anyone know of a workaround to run a task from a task in Prefect 2? I've found some examples of people using .fn but it doesn't appear to work in my case. Specifically, I'd prefer to run trigger_dbt_cli_command from the prefect-dbt package from one of my tasks rather than having to create a flow to run it. I can't change the definition of trigger_dbt_cli_command, since the package itself defines it as a task. I think my problem might be related to the task being async, it seems to finish the execution instantly and the returned type is "None". As long as I'm not using fn(), Prefect will patiently wait for a result, but then I'm forced to call the task from a flow. Edit: If anyone thinks I'm going about this the wrong way, I'd be happy to hear that too. Maybe I just need to settle on always calling trigger_dbt_cli_command from a flow. 🙂
You can’t run a task inside a task. However, you can run a flow inside a flow, so you might want to replace your parent task with a flow instead
Hey @Oscar Björhn Khuyens 100% correct I think if this is really the pattern you want create a subflow would make sense. that said what's the reason behind not wanting to call the trigger_dbt task from within the flow?
Thanks for both of your replies! The reason I wanted to do this is that I had a flow that might be called something like "run dbt" or "run dbt tests" that called another util task I created called run_dbt that sets up all the connection parameters, injects variable in the statement to run and so on before finally calling trigger_dbt_cli_command with the constructed statement. I didn't see a purpose in "run dbt" showing up as its own flow. I created a workaround I'm happy with anyway, I converted run dbt to a function that returned a finished config dictionary instead, that I can easily pass to the trigger_dbt_cli_command task directly from the flow. Just a minor change in how things are set up. I don't mind changing things around for Prefect 2, the new solution isn't worse or better. I just wanted to make sure I wasn't missing something obvious and now I know. 🎉