https://prefect.io logo
Title
m

Mia

01/30/2023, 2:44 PM
Hello, does anyone know how to work with gitlab-repository as a flow storage? I’ve created the gitlab-repository storage and it exists. I have referenced it when i deploy the flow as well. But when I trigger the flow run from the UI, I get this error
Downloading flow code from storage at ''
03:31:49 PM
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: 'example_flow.py'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/prefect/engine.py", line 266, in retrieve_flow_then_begin_flow_run
    flow = await load_flow_from_flow_run(flow_run, client=client)
  File "/usr/local/lib/python3.9/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
    return await fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/prefect/deployments.py", line 186, in load_flow_from_flow_run
    flow = await run_sync_in_worker_thread(load_flow_from_entrypoint, str(import_path))
  File "/usr/local/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 91, in run_sync_in_worker_thread
    return await anyio.to_thread.run_sync(
  File "/usr/local/lib/python3.9/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/usr/local/lib/python3.9/site-packages/prefect/flows.py", line 772, in load_flow_from_entrypoint
    flow = import_object(entrypoint)
  File "/usr/local/lib/python3.9/site-packages/prefect/utilities/importtools.py", line 195, in import_object
    module = load_script_as_module(script_path)
  File "/usr/local/lib/python3.9/site-packages/prefect/utilities/importtools.py", line 158, in load_script_as_module
    raise ScriptError(user_exc=exc, path=path) from exc
prefect.exceptions.ScriptError: Script at 'example_flow.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
g

Guy Altman

01/30/2023, 3:34 PM
How are you deploying? CLI or python file? and where are you executing that? Either way I have seen this error before, for me, I was getting the error when I wasn't running my deployment from a parent location to my flows.
m

Mia

01/30/2023, 3:43 PM
i’m deploying using python file in the parent location of my flows. And I’m executing it in the UI.
so I figured out that the issue was i had the wrong gitlab repository path and token set. I’m using private gitlab repository and it should not be the full repository path but only the the domain, e.g. https://<private-gitlab>.com and the access token should be generated from the gitlab project. You can check whether you can access gitlab with your token by
<https://oauth2>:<access token>@<private-gitlab-url>.com
Now the next issue i’m facing is, how do I make the gitlab block to point to specific repo within the project? I tried running something like
my_repo = GitLabRepository(
             repository=<repository>,
             reference=<my branch name>,
             credentials=gitlab_creds,
)
my_repo.get_directory(from_path="/<gitlab-project-name>/<repo-name>)
my_repo.save("my_repo")
But I’m still getting an error:
File "/usr/local/lib/python3.9/site-packages/prefect_gitlab/repositories.py", line 177, in get_directory
    raise OSError(f"Failed to pull from remote:\n {err_stream.read()}")
Ok I was wrong. I need to give full path to the repo url. So i’m back to original error