b

    Belal Aboabdo

    1 year ago
    Hi All My CI process is failing health checks when building my flow with
    prefect build -p
    with the following error. Anyone experience this issue?
    Beginning health checks...
    System Version check: OK
    Traceback (most recent call last):
      File "/opt/prefect/healthcheck.py", line 150, in <module>
        flows = import_flow_from_script_check(flow_file_paths)
      File "/opt/prefect/healthcheck.py", line 63, in import_flow_from_script_check
        flows.append(extract_flow_from_file(file_path=flow_file_path))
      File "/usr/local/lib/python3.8/site-packages/prefect/utilities/storage.py", line 86, in extract_flow_from_file
        exec(contents, exec_vals)
      File "<string>", line 129, in <module>
    NameError: name '__file__' is not defined
    Michael Adkins

    Michael Adkins

    1 year ago
    Hey @Belal Aboabdo -- are you referencing
    __file__
    in your flow script?
    b

    Belal Aboabdo

    1 year ago
    Yes I am
    Michael Adkins

    Michael Adkins

    1 year ago
    It looks like we're not providing a value for that during load from storage because the flow no longer has a real "file" location -- what are you using it for? (your use-case may justify adding a fake value here)
    b

    Belal Aboabdo

    1 year ago
    Makes sense we're using it to manage our flow configuration here's a snippet:
    if __name__ == "__main__":
    
        flow_params = dict(file_path=os.path.abspath(__file__))
    
        FlowManager(flow, flow_params).do(entry_point())
    Michael Adkins

    Michael Adkins

    1 year ago
    Hm. What are you using for flow storage here?
    (ie
    flow.storage
    )
    b

    Belal Aboabdo

    1 year ago
    We're using Docker storage with aws ecr.
    Michael Adkins

    Michael Adkins

    1 year ago
    I'm trying to reproduce this but the
    __name__
    should not be
    __main__
    when that flow is loaded
    Do you use
    __file__
    else where in your flow code?
    b

    Belal Aboabdo

    1 year ago
    No not within the flow itself.
    Michael Adkins

    Michael Adkins

    1 year ago
    Would it be feasible to DM me your flow script in entirety?
    from prefect import Flow
    from prefect.storage import Docker as DockerStorage 
    
    
    with Flow("test") as flow:
       pass
    
    
    flow.storage = DockerStorage(base_image="prefecthq/prefect:0.14.7")
    
    if __name__ == "__main__":
    
         print(__file__)
    works fine with
    prefect build -p
    b

    Belal Aboabdo

    1 year ago
    Sorry I can't share the script but I can try replicating the issue with the snippet you just sent.
    Michael Adkins

    Michael Adkins

    1 year ago
    That'd be great! A minimal example would be really helpful
    b

    Belal Aboabdo

    1 year ago
    Sorry for the confusion I believe I found the flow that's causing the issue here:
    with Flow(
        flow_name,
        **get_configs(
            file_path=os.path.abspath(__file__), flow_name=flow_name, schedule=sched
        ),
    ) as flow:
    j

    Jacob Hayes

    1 year ago
    I had a similar issue here. Not the exact same (wrong
    __file__
    value rather than
    NameError
    ), but maybe this also has to do with how/if the flows are pickled?
    Michael Adkins

    Michael Adkins

    1 year ago
    Yeah I'm not sure this is an unexpected issue. Using
    __file__
    in your flow declaration like that is a brittle case for us to handle. I'll open an issue to look into it further nonetheless.
    @Marvin open "Docker storage healthcheck fails when using
    __file__
    in flow"
    Marvin

    Marvin

    1 year ago
    b

    Belal Aboabdo

    1 year ago
    Thanks for all the help everyone!