<@ULVA73B9P> what should a function return to imme...
# ask-marvin
j
@Marvin what should a function return to immediately exit and end a prefect flow run in a completed state
m
In Prefect, the final state of a flow run is determined by its return value. Here are the rules: - If an exception is raised directly in the flow function, the flow run is marked as failed. - If the flow does not return a value (or returns None), its state is determined by the states of all of the tasks and subflows within it. - If any task run or subflow run failed, then the final flow run state is marked as FAILED. - If any task run was cancelled, then the final flow run state is marked as CANCELLED. - If a flow returns a manually created state, it is used as the state of the final flow run. This allows for manual determination of final state. - If the flow run returns any other object, then it is marked as completed. So, to immediately exit and end a Prefect flow run in a completed state, you can simply return any object from your flow function. Here's an example:
Copy code
from prefect import Flow

@Flow
def my_flow():
    return "This flow is completed"
You can find more details in the Prefect documentation.