Gregory Hunt
01/23/2025, 6:54 PMMarvin
01/23/2025, 6:54 PMraise_on_failure=False
parameter. This is similar to handling task failures. When you call a subflow, you can capture its result and handle any potential failures gracefully without propagating the failure to the parent flow.
Here's a conceptual example:
python
from prefect import flow
@flow
def subflow_that_may_fail():
# Logic that may fail
raise Exception("This subflow failed!")
@flow
def parent_flow():
try:
result = subflow_that_may_fail()
except Exception as e:
print(f"Subflow failed with error: {e}")
# Handle the failure without failing the parent flow
parent_flow()
This approach allows your parent flow to continue executing even if the subflow encounters an error. You can find more details in the Prefect 2.x documentation.Marvin
01/23/2025, 6:54 PMraise_on_failure=False
parameter on tasks. However, for subflows, you would need to implement a try-except block to catch exceptions from the subflow, as Prefect does not provide a direct raise_on_failure
parameter for flows.
Here's how you can handle it:
python
from prefect import flow
@flow
def subflow_that_may_fail():
# Logic that may fail
raise Exception("This subflow failed!")
@flow
def parent_flow():
try:
subflow_that_may_fail()
except Exception as e:
print(f"Subflow failed with error: {e}")
# Handle the failure without failing the parent flow
parent_flow()
This way, the parent flow can continue executing even if the subflow encounters an error. You can see more about this approach in the Prefect 2.x documentation.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by