I created a custom flow decorator that wraps aroun...
# ask-community
a
I created a custom flow decorator that wraps around the Prefect
@flow
decorator and adds specific functionalities tailored to my use cases, such as deploying to Prefect cloud. One issue I am running into is creating multiple deployments for a single flow. Since I cannot stack multiple decorators on my method, the other way I thought of accomplishing this is by creating multiple variable references to my custom
@flow
wrapper, for example:
Copy code
from toolkit import custom_flow
from prefect import serve, settings, flow

def test_flow():
    print("hello")

deploy1 = custom_flow(
    deployment_name="prod",
    image_name="<http://custom.azurecr.io/app/project:1|custom.azurecr.io/app/project:1>"
)(test_flow)

deploy2 = custom_flow(
    deployment_name="dev",
    image_name="<http://custom.azurecr.io/app/project:2|custom.azurecr.io/app/project:2>"
)(test_flow)
However, when I run the deployments (locally and in the cloud), I get the following error
Copy code
prefect.exceptions.MissingFlowError: Function with name 'test_flow' is not a flow. Make sure that it is decorated with '@flow'.
(running prefect
2.20.10
) I suspect this is because the entrypoint for the deployment is set to be
test_flow
, but in reality it should be
deploy1
and
deploy2
(depending on the deployment we're running). I tested this theory by manually configuring the entrypoint to for each deployment runner and this worked! However, to create a robust solution in my custom flow decorator, I thought I would add a custom
to_deployment
function to that dynamically sets the correct entrypoint based on the flow object name (e.g.,
deploy1
or
deploy2
) instead of the base function name (
test_flow
). Is this the right approach or should I be handling this differently? I know we can define the entrypoint in the deployment yaml config but I want to handle this programmatically within my custom decorator to make the solution more dynamic and reusable, especially when managing multiple deployments for the same flow.
👀 1