I can't seem to find the docs for how to exit a fl...
# ask-community
p
I can't seem to find the docs for how to exit a flow if a specific task fails. Currently I'm raising
signals.FAIL
within the task, but for some tasks I just want to exit a flow if they don't work, and not have to mark every other task dependent on that task succeeding. Anything I can look at?
k
Hi @Philip MacMenamin, have you looked into signals.SKIP? SKIP will also SKIP downstream tasks by default. https://docs.prefect.io/core/concepts/states.html#skip-while-running
p
I saw that, but the docs said:
Skipped states are generally treated as success states
Which led me to believe that this wasn't the standard method to exit a flow in a failed state, upon failure of a critical task. I'd like to mark the task, and flow as failed, and not attempt any further tasks if this one set up task isn't successful. This is the way to do this?
k
Sorry I misunderstood. The Task that you are raising
signal.FAIL
on is not an upstream dependency of the succeeding tasks, but you want those succeeding tasks to not run anymore right?
p
OK, that looks better. It's not clear to me how to set a reference task though,
Copy code
@task
def my_task():
    return "hello"

with Flow("my_flow", reference_tasks=[my_task]) as flow:
    task_1 = my_task()
generates:
Copy code
raise ValueError("reference tasks must be part of the flow.")
ValueError: reference tasks must be part of the flow.
k
How about something like this?
Copy code
from prefect import Flow, task
import prefect

@task
def my_task():
    return "hello"

with Flow("my_flow") as flow:
    task_1 = my_task()

flow.set_reference_tasks([task_1])
flow.run()
p
ok - thanks. This works!