https://prefect.io logo
c

Charles Leung

04/12/2023, 10:33 PM
Hi there, I've been noticing that all of my flows don't have the dependency arrows in the flow graph. Is there a specific way that I should be structuring my code so that I do get these dependency arrows? Using prefect UI version 2.10.3. Sorry for the dumb question, still pretty new to Prefect.
m

Mike Grabbe

04/13/2023, 1:32 AM
I know of two ways for the arrows to show up: 1) set the output variable of one task to be the input variable of another task. 2) use the
wait_for
parameter when calling a task.
wait_for
accepts a list of one or more tasks.
r

Ryan Peden

04/13/2023, 1:43 AM
That sounds right, Mike. I'd only add that this applies to subflows as well as tasks. So you can have a task that depends on the result of a subflow, or vice versa. So if I run code like the following, I get a graph that looks like the attached screenshot.
Copy code
@flow()
def main_flow() -> None:
    result_1 = task_1()
    result_2 = task_2(result_1)
    task_3(result_2)

    sub_flow_result = sub_flow()
    result_4 = task_4(sub_flow_result)
    result_5 = task_5(wait_for=[result_4])
    sub_flow(wait_for=[result_5])
c

Charles Leung

04/13/2023, 4:51 PM
Thanks @Mike Grabbe and @Ryan Peden, I tried following along with my code as below
Copy code
from prefect import flow, task

@task
def task_1():
    pass

@task
def task_2():
    pass

@task
def task_3():
    pass

@flow
def my_flow():
    x = task_1()
    # task 2 will wait for task_1 to complete
    y = task_2(wait_for=[x])
    task_3()
    
if __name__ == "__main__":
   my_flow()
but my flow graph still came out like this. Am I invoking the tasks incorrectly?