Using the @task.external_python() to call a task in a venv fails due to attempting to import airflow and other packages not in the external venv #40763
Replies: 5 comments 2 replies
-
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval. |
Beta Was this translation helpful? Give feedback.
-
It doesn't make much sense to use Airflow imports inside virtual env created to run a task. Converting to discussion as this is a technical question rather than a bug report. |
Beta Was this translation helpful? Give feedback.
-
Hi @eladkal, thanks for the response. That is actually what is confusing me: I am not using @task.external_python(
task_id="create_blend_file",
python=HZ_VENV_PYTHON_PATH,
)
def create_blend_file() -> str:
"""Create and save a simple blend file."""
import bpy
out_file_path = "/tmp/monkey.blend"
bpy.ops.mesh.primitive_monkey_add()
bpy.ops.wm.save_as_mainfile(filepath=out_file_path)
return out_file_path As far as I can tell, this is what the docs seem to indicate I should be doing, and it also seems to match what I have seen others do as well from other examples online... |
Beta Was this translation helpful? Give feedback.
-
I also observe a similar problem while using @task.external_python().
The code of the Airflow task is
|
Beta Was this translation helpful? Give feedback.
-
Look at the parameters of the ExternalPython. There are parameters like "expect_airflow" and "expect_pendulum" and "use_airflow_context". Likely you should look at default values of those parameters and default_args you have to see if they are set to well, EXPECT AIRFLOW and EXPECT PENDULUM |
Beta Was this translation helpful? Give feedback.
-
Apache Airflow version
2.9.2
If "Other Airflow 2 version" selected, which one?
No response
What happened?
It seems like Airflow is trying to run the full dag script inside of the virtualenv, which does not have
airflow
orpendulum
installed inside of it.What you think should happen instead?
Based on the documentation, and other examples I have found online, I would expect it to only run the code inside of the decorated function within the virtualenv.
How to reproduce
Dockerfile
built on top ofapache/airflow:2.9.2
bpy
package runtime requirementspdm
and usepdm
to install Python3.11pdm
installed Python3.11bpy
module to the virtualenv/proc/cpuinfo
which is apparently a longstanding issues with docker/qemu on macOS arm: https://gitlab.com/qemu-project/qemu/-/issues/750--platform linux/amd64
because there are arch mismatch issues that preventbpy
from working on docker on macos when using arm@task.external_python()
decorator to run using the virtualenv in the imageairflow
andpendulum
, which are not installed in the virtualenvbpy
is working properlyOperating System
macOS: 13.6.7 (22G720)
Versions of Apache Airflow Providers
No response
Deployment
Docker-Compose
Deployment details
Customized
Dockerfile
:Click to expand!
The
fakefopen.c
workaround (wouldn't need on an actual deployment):Click to expand!
The test dag:
Click to expand!
The is the log from the Airflow worker container that shows the error:
Click to expand!
Anything else?
I am new to Airflow and am exploring it as an option for integration with our 3D pipeline. I imagine that I am just doing something incorrectly, but I haven't been able to figure out what is wrong, and as far as I can tell, I am doing thing pretty much the same way I have seen in other examples.
Are you willing to submit PR?
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions