Hey all, I'm getting the following error when I tr...
# ask-community
l
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
Can you share your flow definition and how did you register the flow?
l
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
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
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
The second one. You want to create it but not run it
l
@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
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
yikes, still getting the same error! I have added the below snippet after the flow definition.
k
Try assigning it
flow = build_flow1(...)
so that it stays as a variable
l
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
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