You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/06/08 21:43:36 UTC
[airflow] branch main updated: Fix airflow module version check when using ExternalPythonOperator and debug logging level (#30367)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 406b486823 Fix airflow module version check when using ExternalPythonOperator and debug logging level (#30367)
406b486823 is described below
commit 406b486823cbd6bd9748c2311cf3fead047a72aa
Author: Mathieu Bouzard <13...@users.noreply.github.com>
AuthorDate: Thu Jun 8 23:43:08 2023 +0200
Fix airflow module version check when using ExternalPythonOperator and debug logging level (#30367)
---------
Co-authored-by: Tzu-ping Chung <ur...@gmail.com>
Co-authored-by: Jarek Potiuk <ja...@potiuk.com>
---
airflow/__init__.py | 3 +++
airflow/operators/python.py | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/airflow/__init__.py b/airflow/__init__.py
index f0174e5d59..d330b9332a 100644
--- a/airflow/__init__.py
+++ b/airflow/__init__.py
@@ -62,6 +62,9 @@ __path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
# Perform side-effects unless someone has explicitly opted out before import
# WARNING: DO NOT USE THIS UNLESS YOU REALLY KNOW WHAT YOU'RE DOING.
+# This environment variable prevents proper initialization, and things like
+# configs, logging, the ORM, etc. will be broken. It is only useful if you only
+# access certain trivial constants and free functions (e.g. `__version__`).
if not os.environ.get("_AIRFLOW__AS_LIBRARY", None):
settings.initialize()
diff --git a/airflow/operators/python.py b/airflow/operators/python.py
index 4158db2895..23553e5a89 100644
--- a/airflow/operators/python.py
+++ b/airflow/operators/python.py
@@ -727,7 +727,10 @@ class ExternalPythonOperator(_BasePythonVirtualenvOperator):
try:
result = subprocess.check_output(
- [self.python, "-c", "from airflow import __version__; print(__version__)"], text=True
+ [self.python, "-c", "from airflow import __version__; print(__version__)"],
+ text=True,
+ # Avoid Airflow logs polluting stdout.
+ env={**os.environ, "_AIRFLOW__AS_LIBRARY": "true"},
)
target_airflow_version = result.strip()
if target_airflow_version != airflow_version: