Luis Cebrián
08/28/2024, 7:36 PMFlow could not be retrieved from deployment.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/prefect/engine.py", line 310, in retrieve_flow_then_begin_flow_run
flow = await load_flow_from_flow_run(flow_run, client=client)
File "/usr/local/lib/python3.8/site-packages/prefect/client/utilities.py", line 40, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/deployments.py", line 204, in load_flow_from_flow_run
output.update(await run_step(step))
File "/usr/local/lib/python3.8/site-packages/prefect/projects/steps/core.py", line 77, in run_step
step_func = _get_function_for_step(fqn, requires=keywords.get("requires"))
File "/usr/local/lib/python3.8/site-packages/prefect/projects/steps/core.py", line 29, in _get_function_for_step
step_func = import_object(fully_qualified_name)
File "/usr/local/lib/python3.8/site-packages/prefect/utilities/importtools.py", line 212, in import_object
module = load_module(module_name)
File "/usr/local/lib/python3.8/site-packages/prefect/utilities/importtools.py", line 183, in load_module
return importlib.import_module(module_name)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 970, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'prefect.deployments.steps'; 'prefect.deployments' is not a package
What is happening here?Luis Cebrián
08/28/2024, 7:42 PMprefect.yaml
: prefect deploy --name "datalake-export-run-exports"
name: export-datalake
prefect-version: 2.20.3
# build section allows you to manage and build docker images
build:
- prefect_docker.deployments.steps.build_docker_image:
id: build_image
requires: prefect-docker>=0.5.4
image_name: europe-docker.pkg.dev/project-id/image-name
tag: latest
dockerfile: ../../../docker/Dockerfile.extended
# push section allows you to manage if and how this project is uploaded to remote locations
push:
- prefect_docker.deployments.steps.push_docker_image:
requires: prefect-docker>=0.5.4
image_name: '{{ build_image.image_name }}'
tag: '{{ build_image.tag }}'
pull:
- prefect.deployments.steps.set_working_directory:
directory: /opt/prefect
definitions:
work_pools:
gcp_push: &gcp_push
name: gcp-cloud-run-push
work_queue_name:
job_variables:
image: '{{ build_image.image }}'
deployments:
- name: datalake-export-run-exports
entrypoint: flow.py:run_export_jobs
work_pool: *gcp_push
version:
tags: []
description: Runs a job export for every export configured
parameters: {}
schedules:
- cron: 0 7 * * *
timezone: UTC
day_or: true
active: true
The code is baked in the docker image and the dockerfile pretty much installs a requirements.txt file and copies the flow code
FROM europe-docker.pkg.dev/data-genially/prefect/prefect-base:2.20.3-utils0.2.3-python3.12 # this is a prefect image with some utilities installed
COPY requirements.txt .
RUN pip install -r requirements.txt
# Copy python files
COPY . /opt/prefect
As you can see, I'm running prefect 2.20.3 on python 3.12. The thing is that the stack trace shows that is running python 3.8 for some reason. :SLuis Cebrián
08/28/2024, 7:43 PMNate
08/28/2024, 7:54 PMprefect version
command inside the container?
europe-docker.pkg.dev/data-genially/prefect/prefect-base:2.20.3-utils0.2.3-python3.12im not sure what you ahve in there, but this very much seems like a version issue to me
ModuleNotFoundError: No module named 'prefect.deployments.steps'; 'prefect.deployments' is not a package
unless somehow there's some namespace overlap thingLuis Cebrián
08/28/2024, 7:56 PMdocker run -it europe-docker.pkg.dev/project-id/image-name:latest bash
root@23033f72e8fb:/opt/prefect# prefect version
Version: 2.20.3
API version: 0.8.4
Python version: 3.12.5
Git commit: b8c27aa0
Built: Thu, Aug 22, 2024 3:13 PM
OS/Arch: linux/x86_64
Profile: default
Server type: ephemeral
Server:
Database: sqlite
SQLite version: 3.40.1
Luis Cebrián
08/28/2024, 7:57 PMim not sure what you ahve in there, but this very much seems like a version issue to meIt happens sometimes and sometimes not without redeploying or rebuilding the image, that's the weird part.
Luis Cebrián
08/28/2024, 8:00 PMNate
08/28/2024, 8:09 PMFile "/usr/local/lib/python3.8/site-packages/prefect/projects/steps/core.py", line 77, in run_step
step_func = _get_function_for_step(fqn, requires=keywords.get("requires"))
File "/usr/local/lib/python3.8/site-packages/prefect/projects/steps/core.py", line 29, in _get_function_for_stephmm interesting so looking closer actually this has to be a version thing
prefect/projects
does not exist in prefect 2.20.3Nate
08/28/2024, 8:10 PMNate
08/28/2024, 8:11 PMeurope-docker.pkg.dev/data-genially/prefect/prefect-base:2.20.3-utils0.2.3-python3.12
Nate
08/28/2024, 8:12 PMLuis Cebrián
08/28/2024, 8:13 PMi would be suspicious of however this image gets builtThat image is built as follows:
ARG PREFECT_VERSION
ARG PYTHON_VERSION
FROM prefecthq/prefect:${PREFECT_VERSION}-python${PYTHON_VERSION}
# Install dependencies to be able to install private packages
RUN apt-get -yq update && apt-get -yqq install openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan <http://github.com|github.com> >> ~/.ssh/known_hosts
RUN pip install --upgrade pip
# Install dependencies
RUN --mount=type=ssh,id=githubkey pip install <git+ssh://git@github.com/some-private-repo.git@v0.2.3>
And the prefect version / python version is what the name of the image has.Nate
08/28/2024, 8:16 PMpull
step action that uses run_shell_script
to echo pip freeze | grep prefect
or somethingNate
08/28/2024, 8:16 PMNate
08/28/2024, 8:17 PMLuis Cebrián
08/28/2024, 8:17 PMLuis Cebrián
08/28/2024, 8:23 PMdocker run -it europe-docker.pkg.dev/project-id/image-name:latest bash
root@0573ea7b877f:/opt/prefect# cd /usr/local/lib/
root@0573ea7b877f:/usr/local/lib# ls
libpython3.12.so libpython3.12.so.1.0 libpython3.so pkgconfig python3.12
Luis Cebrián
08/28/2024, 8:45 PMNate
08/28/2024, 8:45 PMLuis Cebrián
08/28/2024, 8:46 PMKevin Grismore
08/28/2024, 10:18 PMLuis Cebrián
08/29/2024, 5:27 AMLuis Cebrián
08/29/2024, 9:19 AMprefect.yaml
).
• Solved it by telling the agent to pickup work from the "default-agent-pool" work pool.
Thanks @Nate and @Kevin Grismore for your help. I really appreciate it.