https://prefect.io logo
m

Mansour Zayer

03/10/2023, 6:50 PM
Hello. In prefect2, I have different behavior locally vs a cloud flow run: I'm defining a few flows with the same functionality like this (I'm using
Flow
instead of
@flow
):
Copy code
def create_flow(flow_name, param):
    def general_func(param):
        do_something(param)

    return Flow(general_func, name=flow_name)

my_flow_1 = create_flow(flow_name="my_flow_1", param=ex_1)
my_flow_2 = create_flow(flow_name="my_flow_2", param=ex_2)
Now this works fine locally. But when I deploy to the Prefect cloud, I get this error when I run the flow (deployment is fine):
raise MissingFlowError(prefect.exceptions.MissingFlowError: Flow function with name 'general_func' not found in {my directory}.
Why is it expecting a flow called
general_func
? How can I fix this? p.s. I don't want my general_func to be a subflow. Thanks
1
z

Zanie

03/10/2023, 9:28 PM
We need to be able to import the flow and the default entrypoint is generated like so: https://github.com/PrefectHQ/prefect/blob/main/src/prefect/deployments.py#L755
You’ll want to set an entrypoint to import
my_flow_#
instead of us inferring it from the function attached to the flow
m

Mansour Zayer

03/13/2023, 5:17 PM
Thanks for your reply. If I understand correctly, I removed the
create_flow
layer, so it would be:
Copy code
## flows.py
def general_func(param):
  do_something(param)

my_flow_1 = Flow(general_func, name="my_flow_1")
my_flow_2 = Flow(general_func, name="my_flow_2")
And imported them in the deployment script:
Copy code
## directory overview
- flows.py
  - general_func
  - my_flow_1
  - my_flow_2

- deployment.py
  - import my_flow_#
  - build_from_flow()
But I still get
raise MissingFlowError(prefect.exceptions.MissingFlowError: Function with name 'general_func' is not a flow. Make sure that it is decorated with '@flow'.
Is it even possible to create multiple flows from the same function like I'm trying to do with
Flow
?
z

Zanie

03/13/2023, 5:39 PM
You need to set the Deployment’s entrypoint
m

Mansour Zayer

03/13/2023, 8:22 PM
Ok Thanks. Explicitly defining the entrypoint fixed it.