i’ve got a task that depends on two other prior ta...
# ask-community
m
i’ve got a task that depends on two other prior tasks, how can i get the child task to only start after both parents have finished (i wanted to combine the output of both tasks into a single arg instead of adding a new arg)? i tried using a simple boolean
and
(the output of each task is a bool), but it looks like prefect started the child task when the first parent finished instead of waiting for both:
Copy code
FIRST_TASK_DONE = first_task()
SECOND_TASK_DONE = second_task()

THIRD_TASK_READY = FIRST_TASK_DONE and SECOND_TASK_DONE
third_task(third_task_ready=THIRD_TASK_READY)
third_task
was supposed to only start after both
first_task
and
second_task
had finished, but instead it only waited for the first one to complete
k
Hey @Martim Lobao, I think you want to explicitly set both as upstream dependencies.
Copy code
with Flow(...) as flow:
     a = first_task()
     b = second_task()

     c = third_task(c_inputs, upstream_tasks=[a,b])
m
alright, so a list will work as intended then?
k
List for
upstream_tasks
will work yeah. If
a
and
b
are mapped, you may need to wrap them with
unmapped
inside the list
m
we’re using the functional api btw
would that still work?
k
I think my example is the functional? You mean imperative (or whatever does not use the Flow block)? Yes it would work. If it doesn’t, you can also do:
Copy code
with Flow(...) as flow:
     a = first_task()
     b = second_task()

     c = third_task()
     c.set_upstream(b)
     c.set_upstream(a)
m
ah, got it, i think i was thrown off by the fact that
upstream_tasks
is an argument of
set_dependencies
thanks 👍
k
Oh it isn’t. It’s a reserved keyword added to the
run()
method of tasks
m
got it, thanks @Kevin Kho 🙂