<@ULVA73B9P> is it possible to manually complete a...
# ask-marvin
c
@Marvin is it possible to manually complete a flow from within the flow definition code?
m
In Prefect, Flows are like functions. They can take inputs, perform work, and return an output. You can turn any function into a Prefect flow by adding the @flow decorator. When a function becomes a flow, its behavior changes. All runs of the flow have persistent state and transitions between states are recorded. This allows for flow execution to be observed and acted upon. However, the documentation does not directly address the possibility of manually completing a flow from within the flow definition code. It might be possible depending on the specific use case and how the flow is structured. For a more specific answer, you might want to reach out to the Prefect community or support.
n
you can return a
Completed
state @Marvin find docs on final state determination
m
The final state of a flow in Prefect 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. There are terminal state types from which there are no orchestrated transitions to any other state type. These include COMPLETED, CANCELLED, FAILED, and CRASHED. For more details, you can check the Prefect documentation on states.
n
Copy code
In [1]: from prefect import flow

In [2]: from prefect.states import Completed

In [3]: @flow
   ...: def foo():
   ...:     return Completed(message="feeling lazy")
   ...:

In [4]: foo()
14:56:47.390 | INFO    | prefect.engine - Created flow run 'impressive-agouti' for flow 'foo'
14:56:48.403 | INFO    | Flow run 'impressive-agouti' - Finished in state Completed('feeling lazy')
c
thanks @Nate - just taking a look at the docs. The import in the docs show (latest):
Copy code
from prefect.server.schemas.states import Completed
n
thats not right, we'll have to update that
n
you should use
from prefect.states import <SomeState>
generally you should avoid using the server schemas
c
Okay- thanks. That’s good to know.
n
PR to update docs - thanks for the callout!
🙌 1