What is the best way for a flow to run to successf...
# best-practices
s
What is the best way for a flow to run to successful completion even if one of the tasks fail
I have looked at these places 1, 2, 3
It seems like the best way is to to use your try and except clause here
n
hi @Saad Bin Akhlaq -
return_state
is useful for this
Copy code
In [1]: from prefect import task, flow

In [2]: @task
   ...: def terrible():
   ...:     raise ValueError('oops')
   ...:

In [3]: @flow
   ...: def f():
   ...:     state = terrible(return_state=True)
   ...:     assert state.is_failed()
   ...:     return "and its ok"
Copy code
10:09:26.182 | ERROR   | Task run 'terrible-0' - Finished in state Failed('Task run encountered an exception ValueError: oops')
10:09:26.300 | INFO    | Flow run 'masterful-wrasse' - Finished in state Completed()
Out[4]: 'and its ok'
s
thanks for this, I think the main issue was that there wasn't a return statement in the failing task