i.e. make task a an implicit dependency of task b,...
# prefect-community
d
i.e. make task a an implicit dependency of task b, even though no data flows from a to b
1
n
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
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
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
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
Yep, you have a couple of options here. You can explicitly declare tasks and upstream/downstream dependencies like this naive example:
Copy code
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:
Copy code
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!