I remember reading a Prefect doc about how to set ...
# ask-community
h
I remember reading a Prefect doc about how to set additional reference tasks (other than default final one) but can’t find it now. How would I add a reference task to a flow?
s
You can either pass the tasks in through the Flow constructor OR use the set_reference_tasks method on the flow https://docs.prefect.io/api/latest/core/flow.html#flow-2
upvote 2
k
Sam is spot on. It would be
flow.set_reference_tasks([c])
where c is a task inside your Flow.
👍 1
h
@Kevin Kho One thing I’ve found is c has to be an output of a task, so if I have a task that I want to set as a reference
Copy code
output = reference_task(input)
I have to set the reference task as
Copy code
flow.set_reference_tasks(tasks = [output])
which to me, is a bit clunky. Is there a way to specify the task and not the output as an argument to the
set_reference_task
method?
k
Unfortunately, no, only the output can be passed.
h
what about with task slugs?
k
Let me check
It might be ugly. I think this works:
Copy code
with Flow("xxx") as flow:
    a = abc(1)
    b = abc(2, upstream_tasks=[a])
    bcd(2)

flow.set_reference_tasks([flow.get_tasks(name="bcd")[0]])
h
ok, thanks. I see. may just stick with the first option then haha
😅 1