https://prefect.io logo
l

Lee Cullen

02/22/2022, 9:11 PM
Hey all, I'm getting the following error when I try to run a flow via cloud using Bitbucket storage config:
Failed to load and execute Flow's environment: ValueError('No flows found in file.')
. The flow context manager is defined within the body of a function that returns a flow, I'm wondering if that is the reason why cloud can't find the flow?
a

Anna Geller

02/22/2022, 9:38 PM
Can you share your flow definition and how did you register the flow?
l

Lee Cullen

02/22/2022, 9:51 PM
Hey Anna, sure. I register flows using a python file called register.py which basically does the following: 1. import flow1 i.e from flow1.py import build_flow1. 2. Calls a function, register_flow(flow) that i pass build_flow1 to and executes the following:
return flow.register(project_name=prefect_cloud_project, idempotency_key=flow.serialized_hash())
Registering the flow is automatically triggered every time I make a commit using bitbucket pipelines. Let me know if you need anymore info.
k

Kevin Kho

02/22/2022, 10:02 PM
Hey Lee, so if you use a function that creates the Flow, you need to run it because Prefect goes into the file, executes it, and looks for Flow objects in the global namespace so call
build_flow1
in this file.
l

Lee Cullen

02/22/2022, 10:10 PM
Thanks Kevin, so it's as simple as replacing
return flow
with
return flow.run()
?
Or rather:
Copy code
if __name__ == "__main__":
    build_flow1(env, cache)
k

Kevin Kho

02/22/2022, 10:48 PM
The second one. You want to create it but not run it
l

Lee Cullen

02/22/2022, 10:50 PM
@Kevin Kho I've tried adding both of the below segments to the end of build_flow1 but I'm still getting the same error when I try to run the flow via cloud.
k

Kevin Kho

02/22/2022, 10:52 PM
Ah I see actually not in the
Copy code
if __name__ == "__main__":
I guess it’s not called by Prefect when it goes it and loads in the file. Just return the Flow and call
build_flow1
(just go get the flow object in the global namespace). It won’t run anything anyway
l

Lee Cullen

02/22/2022, 11:26 PM
yikes, still getting the same error! I have added the below snippet after the flow definition.
k

Kevin Kho

02/23/2022, 12:15 AM
Try assigning it
flow = build_flow1(...)
so that it stays as a variable
l

Lee Cullen

02/23/2022, 12:37 AM
Genuis! Your mate George was very impressed with your solution. I was screen sharing whilst I tried the variable assignment recommended above and it worked a treat.
k

Kevin Kho

02/23/2022, 12:40 AM
Lol it’s just cuz the code path looks for variables on type Flow in the global namespace so you need it as a variable
🙌 1
7 Views