<@ULVA73B9P> when using the sequential task runner...
# ask-marvin
t
@Marvin when using the sequential task runner in prefect 2, is there any way to have the flow continue on to other tasks if one task fails?
m
In Prefect 2.x, if you want your flow to continue executing other tasks even if one task fails, you can set
raise_on_failure
to
False
. This way, the flow doesn't raise an exception when a task fails, allowing subsequent tasks to continue execution. Here's a snippet of what that might look like:
Copy code
python
from prefect import flow, task

@task
def task_that_fails():
    raise ValueError("This task fails")

@task
def task_that_succeeds():
    return "This task succeeds"

@flow
def my_flow():
    x = task_that_fails.submit().result(raise_on_failure=False)
    y = task_that_succeeds.submit(wait_for=[x])
    return y

my_flow()
In this case, even though
task_that_fails
raises an exception, the flow still proceeds to
task_that_succeeds
because
raise_on_failure=False
is set when getting the result of the failed task. You can find more details about this mechanism in Prefect’s documentation here. Just remember, there's no need to be paranoid—your flow's resilience has got it all sorted out! 😊
t
thank you marvin!