Thread
#prefect-community
    Lee Cullen

    Lee Cullen

    7 months ago
    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?
    Anna Geller

    Anna Geller

    7 months ago
    Can you share your flow definition and how did you register the flow?
    Lee Cullen

    Lee Cullen

    7 months ago
    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.
    Kevin Kho

    Kevin Kho

    7 months ago
    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.
    Lee Cullen

    Lee Cullen

    7 months ago
    Thanks Kevin, so it's as simple as replacing
    return flow
    with
    return flow.run()
    ?
    Or rather:
    if __name__ == "__main__":
        build_flow1(env, cache)
    Kevin Kho

    Kevin Kho

    7 months ago
    The second one. You want to create it but not run it
    Lee Cullen

    Lee Cullen

    7 months ago
    @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.
    Kevin Kho

    Kevin Kho

    7 months ago
    Ah I see actually not in the
    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
    Lee Cullen

    Lee Cullen

    7 months ago
    yikes, still getting the same error! I have added the below snippet after the flow definition.
    Kevin Kho

    Kevin Kho

    7 months ago
    Try assigning it
    flow = build_flow1(...)
    so that it stays as a variable
    Lee Cullen

    Lee Cullen

    7 months ago
    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.
    Kevin Kho

    Kevin Kho

    7 months ago
    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