https://prefect.io logo
Title
d

David Hogarty

04/28/2020, 1:55 PM
i.e. make task a an implicit dependency of task b, even though no data flows from a to b
1
n

nicholas

04/28/2020, 1:57 PM
Hi @David Hogarty, you definitely can! For that you can use the
upstream_tasks
kwarg, which will explicitly set that dependency. You can read more about it here.
d

David Hogarty

04/28/2020, 1:58 PM
how do I use that within the functional api?
do I just do b(regular_params, upstream_tasks=[a])
?
or, i guess
b_res = b(...)
err a_res = a(...)
b_res = b(..., upstream_tasks=[a_res])
z

Zachary Hughes

04/28/2020, 2:01 PM
Hi David! If you want to operate within the functional API, you can also use
task.set_upstream
to explicitly define which tasks are upstream and downstream of each other. https://docs.prefect.io/api/latest/core/task.html#task-2
:upvote: 1
d

David Hogarty

04/28/2020, 2:32 PM
roger, so when I have a @prefect.task
and call it from within the functional api, its return is a Task object?
and consequently, I can use the return from a task invocation for set_upstream or the upstream_tasks kwarg?
makes sense
i think this solved my problem
z

Zachary Hughes

04/28/2020, 2:53 PM
Yep, you have a couple of options here. You can explicitly declare tasks and upstream/downstream dependencies like this naive example:
f = Flow(name="test")
t1 = Task()
t2 = Task()
t2.set_upstream(t1, flow=f)
or you can pass them in as arguments, like in this example:
with Flow("Example Flow") as flow:
    task_a = task_a()
    task_b = task_b(upstream_tasks=[task_a])
It really just depends on your style and use case. Sounds like you're on the right track, but don't hesitate to reach out if you have any more questions!