Hi We are trying to integrate our prefect flows wi...
# ask-community
s
Hi We are trying to integrate our prefect flows with github. But I am getting segmentation fault while trying to deploy. And on running the flow it give below E*rror,* Could you please help me idenitify the issue here?
Copy code
State Message
Flow could not be retrieved from deployment. Traceback (most recent call last): File "<frozen importlib._bootstrap_external>", line 846, in exec_module File "<frozen importlib._bootstrap_external>", line 982, in get_code File "<frozen importlib._bootstrap_external>", line 1039, in get_data FileNotFoundError: [Errno 2] No such file or directory: 'flow_name.py' The above exception was the direct cause of the following exception: ScriptError: Script at 'flow_name.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
Below is our dir structure in github
Copy code
└── src
    ├── dev
    │   └── flows
    │       ├── flow
    │       │   ├── README.md
    │       │   ├── flow_name.py
    │       │   ├── flow_deployment.py
And the deployment file is like this
Copy code
from flow import flow
from prefect.blocks.system import JSON
from prefect.deployments import Deployment
from prefect.filesystems import GitHub

storage = GitHub.load("gh-poc")

FLOW_NAME = "flow_name"


deployment = Deployment.build_from_flow(
    flow=flow_name,
    name=FLOW_NAME,
    parameters={},
    storage=storage,
    path="src/dev/flows/flow_name",
    skip_upload=True,
)

if __name__ == "__main__":
    deployment.apply()
    print("Deployment applied")
c
The path you are using doesn’t look relative to root? The path of the actual flow from your directory looks like:
/src/dev/flows/flow/flow_name
But the path supplied is
path="src/dev/flows/flow_name",
you should have like:
Copy code
path=/src/dev/flows/flow,
entrypoint=flow_name.py:<flow definition function>
s
Does it also depend on from which directory I am running the deployment?
Currently I am running it from innermost dir (flow)
c
if you are importing the flow, that’s relevant to the path, but otherwise those variables are important for how to retrieve the flow
thank you 1
in other words, where you register and apply the deployment is irrelevant other than your path for importing the flow
but the path and entrypoint are necessary to be accurate and match the path they would be retrieved from
👍 1
based on your
path
it’s being retrieved from
/src/dev/flows/flow_name
from the github block
yess 1
s
It worked after setting entrypoint. Ran with this
path="src/dev/flows/flow_name",
🙌 1
m
I'm running into a similar issue where the files and flows cannot be found. How can I ensure it is pulling the github repo and proper branch? I believe the docker image is in /opt/prefect, however I'm not sure where it is cloning the flow into.
Copy code
Downloading flow code from storage at 'performance-aggregation-table'
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/performance-aggregation-table'
Copy code
└── githubrepo
    ├── performance-aggregation-table
    │   └── performance_aggregation_table.py
Copy code
github_block = GitHub(
            repository = "XXX",
            reference = "github-test", #Branch name
            access_token ="XXX",
        )
Copy code
deployment = Deployment.build_from_flow(
            path="performance-aggregation-table",
          entrypoint="performance_aggregation_table.py:run_perf_agg",
I have tried a multitude of including path, not including path, etc.
c
HI Mitch -
/opt/prefect
would be the default working directory that a clone would occur into
so
/opt/prefect
will contain the directory of the GitHub block, which would then contain your flow
what is the path of your flow in the repo
so if your repo is called
test-repo
then the path is
/opt/prefect/test-repo
and the entrypoint is
performance_aggregation_table.py:run_perf_agg
m
Got it. I will give it a try. Thanks Christopher
Still getting the same error. Path to my flow within the repo
position-pnl-pipeline
is
performance-aggregation-table/performance_aggregation_table.py
path="/opt/prefect/position-pnl-pipeline/performance-aggregation-table",
entrypoint="performance_aggregation_table.py:run_perf_agg",
Copy code
Downloading flow code from storage at '/opt/prefect/position-pnl-pipeline/performance-aggregation-table'

Flow could not be retrieved from deployment.
Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/prefect/engine.py", line 395, in retrieve_flow_then_begin_flow_run
    flow = await load_flow_from_flow_run(flow_run, client=client)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
    return await fn(*args, **kwargs)
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/prefect/deployments/deployments.py", line 199, in load_flow_from_flow_run
    await storage_block.get_directory(from_path=deployment.path, local_path=".")
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/prefect/filesystems.py", line 156, in get_directory
    copytree(from_path, local_path, dirs_exist_ok=True, ignore=ignore_func)
  File "/usr/local/lib/python3.10/shutil.py", line 557, in copytree
    with os.scandir(src) as itr:
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/position-pnl-pipeline/performance-aggregation-table'
I am thoroughly confused, but there is probably a simple fix
c
Out of curiosuity, have you tested using the new
prefect deploy
way? I’ll be honest, it’s been a hot minute since I’ve done the pythonic deployment + a github repo block, so it’s possible my steps aren’t right here either. It looks like it’s trying to download from that path (first line) not the cloned repo
m
From the CLI? No, we are migrating everything over from prefect 1 so just have been trying to setup everything to make it easiest. We have around 150 scripts and it gets complicated managing all of them and having to use the cli to deploy everything
Can you point me to someone who is more familiar with it? We use prefect enterprise and this is holding us up
c
Hey Mitch, if you’re using enterprise, you should have access to support@prefect.io and the team should be able to assist you
1
m
It appears that when I specify a path, the code is not downloaded from github.