<@ULVA73B9P> In prefect 2.x is is possible to call...
# ask-marvin
g
@Marvin In prefect 2.x is is possible to call a subflow that can fail, but doesn't fail the parent flow. Similar to the way a task can raise_on_failure=False
m
In Prefect 2.x, you can handle subflow failures without failing the parent flow by using the
raise_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:
Copy code
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.
In Prefect 2.x, you can handle subflow failures without failing the parent flow by using the
raise_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:
Copy code
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.