Hello folks, I keep getting this error when tryin...
# prefect-cloud
a
Hello folks, I keep getting this error when trying to run a deployment in Prefect Cloud :
Copy code
Flow could not be retrieved from deployment.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 154, in run_steps
    step_output = await run_step(step, upstream_outputs)
  File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 125, in run_step
    result = await from_async.call_soon_in_new_thread(
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 327, in aresult
    return await asyncio.wrap_future(self.future)
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 352, in _run_sync
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 311, in coroutine_wrapper
    return call()
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 432, in __call__
    return self.result()
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 318, in result
    return self.future.result(timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 179, in result
    return self.__get_result()
  File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 389, in _run_async
    result = await coro
  File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/pull.py", line 123, in git_clone
    await storage.pull_code()
  File "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 233, in pull_code
    await self._clone_repo()
  File "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 241, in _clone_repo
    repository_url = self._repository_url_with_credentials
  File "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 167, in _repository_url_with_credentials
    for k, v in credentials.items():
AttributeError: 'str' object has no attribute 'items'
I don't really know where the problem is coming from, as it seems to come from Prefect's modules and not something I wrote. Here is the .yaml of my deployment :
Copy code
name: tenacy-prefect
prefect-version: 2.20.2

# build section allows you to manage and build docker images
build:

# push section allows you to manage if and how this project is uploaded to remote locations
push:

# pull section allows you to provide instructions for cloning this project in remote locations
pull:
- prefect.deployments.steps.git_clone:
    repository: <https://my-private-gitlab-instance.io/data/tenacy-prefect.git>
    credentials: '{{prefect.blocks.secret.gitlab-personal-token}}'


# the deployments section allows you to provide configuration for deploying flows
deployments:
- name: Younium
  version:
  tags: []
  description:
  entrypoint: flows/flows.py:younium_flow
  parameters: {}
  work_pool:
    name: tenacy-work-pool
    work_queue_name:
    job_variables: {}
  schedules: []
j
Hey! Could you try replacing
Copy code
credentials: '{{ ... }}'
with
Copy code
access_token: '{{ ... }}'
?
a
I tried, but I get this error instead :
Copy code
RuntimeError: Failed to clone repository '<https://my-private-gitlab-instance.io/data/tenacy-prefect.git>' with exit code 128.
It seems that with
credentials
it managed to clone the repo but got stuck somewhere else.
Intuitively, it's like Prefect Cloud cannot find the flow, maybe the entrypoint is wrong ? But I got it from the CLI
This is the flow btw, a simple Gitlab pipeline trigger :
Copy code
@flow(log_prints=True, name='Younium Extract')
def younium_flow():
    secret_block = Secret.load("younium-pipeline-token")
    pipeline_token = secret_block.get()
    project_id = 64
    pipeline_id = trigger_pipeline(project_id=project_id, pipeline_token=pipeline_token)
    get_pipeline_status(project_id=project_id, pipeline_id=pipeline_id)
j
With
credentials
it error'ed before it was able to even clone, because you're passing a
Secret
block instead of a
GitLabCredentials
block
Can double check that 1. you have a
Secret
block named
gitlab-personal-token
and that stored token has access to your repo? 2. your yaml looks like the following, including quotes and spaces:
Copy code
access_token: "{{ prefect.blocks.secret.gitlab-personal-token }}"
the 128 means it is unable to authenticate, whether from your token, or it's not being templated correctly
a
I have the secret block and my token should be valid.
šŸ‘ 1
I'll try with the token hardcoded to see if it fixes it
Same error with the hardcoded token, weird. I have to go to the gym, but maybe I'll have an illumination there haha. Thanks for the help !
@Jake Kaplan I don't think the problem comes from my token, as I was able to call the Gitlab API with it
(even though I don't know exactly what route Prefect is calling)
Hey @Jake Kaplan! I'm very sorry, but I forgot something very important. Our Gitlab instance is not accessible from the open internet, you need to be on our network to clone the repo. My bad, I was a bit tired yesterday. Is there a list of IP we can whitelist ? I saw this : https://linen.prefect.io/t/2437799/u01hknraapq-dig-http-api-prefect-io-api-prefect-io-returns-a but that's it.
I managed to make it work using a Docker image, let's goooo šŸ”„
j
hey! sorry for delayed reply here. I'm glad you were able to get it working!
a
No worries, I imagine we're not in the same timezone. One last question, I'm having trouble picturing the purpose of Prefect Cloud if I still have to host my docker image somewhere. Using Prefect Cloud simply allows me not to have to host a database instance and the API, right ? I'm running the docker image like this :
Copy code
docker run -e PREFECT_API_URL=$PREFECT_API_URL -e PREFECT_API_KEY=$PREFECT_API_KEY prefect-tenacy
It works on my machine, but I imagine it will work as well when we host it on our infra, because in that case it will be us calling the Prefect API, and not Prefect trying to clone our repo. Have I understood correctly ?
j
Correct, you can think of Prefect Cloud as a hosted version of the prefect orchestration server/db. The code execution however happens in your environment (which is when code is pulled, if you're using git remote storage or just loaded if you're using an image).
a
Okay, so the API hosted by Prefect Cloud will trigger the docker image hosted on our servers ? Which means we still need to whitelist Prefect's IP range ? edit : sorry for all those questions, I'm not used to handling the dataops side of data engineering šŸ˜›
j
No worries! Prefect uses a hybrid approach whether you are using prefect cloud or hosting the api yourself. Workers: • are long running process that lives in your infrastructure • it polls the api for new runs in your work pool • when it finds a new run it will deploy and execute the run to your infrastructure (defined by your work pool) Prefect isn't calling into your infrastructure directly, the worker and execution environments will be reaching out to prefect cloud. What you need to do for that depends on your network setup. We publish our ip here. It depends on your security setup but most commonly I think people whitelist the prefect api uri for outbound trarffic.
a
Thanks a lot for the link and the explanation !
j
np!