https://prefect.io logo
Title
j

John Kang

08/29/2022, 4:58 PM
I have a large flow that I use to query data, transform it, test it, and insert it into a database (with each of these steps as either tasks or sub-flows). My question is what is a best practice regarding: 1. Failing the entire flow if one part of the flow (a sub flow or task) fails? I want the entire flow to fail if the testing discovers an issue with the data (I have custom Pandera data checks setup because our database frequently experiences failures). I've thought about passing an exception to each subsequent task/sub-flow but that seems cumbersome. 2. Emailing details regarding failures. I've setup a custom function to email exceptions if they occur. Should I just insert a try/except for each task/sub-flow? I think that would work, but wasn't sure if there was a better method.
r

Rob Freedy

08/29/2022, 7:35 PM
Hey John!! I assume these are related to 2.0 but happy to answer about 1.0 as well! 1. If a flow does not return a value, then its state is determined by all of the tasks and will fail if one of the tasks fails. If it does return a value, then any exceptions will trigger a flow failure or you can set the state manually if the value is not the expected one: https://docs.prefect.io/concepts/states/#final-state-determination 2. For 2.0, you can set up notifications on a failed state change as shown in the example below for a simple message. You could use something similar to what you described and uses the Prefect email collection to send a notification with the exception message and anything you would like for a more detailed email message: https://docs.prefect.io/ui/notifications/?h=trigg https://prefecthq.github.io/prefect-email/
j

John Kang

08/29/2022, 9:16 PM
@Rob Freedy Thanks for the note. This makes a lot of sense for 2.0. Any tips on what to do if sub-flows fail? I would like the sub-flow failure to cause the subsequent tasks/sub-flows to fail as well. Should I just pass on the state using the
return_stat=True
parameter? So if the state has an exception it will fail the entire flow? Thanks for the help! Also, appreciate the note about notifications. I've setup a custom function, but will look at this collection to see if it makes it any easier.
r

Rob Freedy

08/29/2022, 10:00 PM
A failing subflow should cause the state of the parent flow to be marked as failed. You could use the return_state=True if you wanted to return the states of the subflow and do something with them. If you want to set dependencies between sub flows you could use wait_for as well: https://discourse.prefect.io/t/how-can-i-create-a-subflow-and-block-until-it-s-completed/94 TLDR the default behavior is that a subflow fails then the parent flow will fail, and you can set dependencies between subflows/tasks with wait_for in 2.0