This is an automated email from the ASF dual-hosted git repository. ash pushed a commit to branch log-var-and-conn-from-venv-take-two in repository https://gitbox.apache.org/repos/asf/airflow.git
commit dca52ee89b8106a0d05d8f20715571f0f84592bf Author: Ash Berlin-Taylor <[email protected]> AuthorDate: Mon Nov 10 15:40:27 2025 +0000 Allow virtualenv code to access connections/variables and send logs (This is the second attempt at this PR) This change is quite simple, as it simply calls the function added in #57212 and #58147 if it's available. Up until the point that it is released this code will not hit the getattr will return None and be a no-op. I didn't use the walrus operator here as theoretically someone could be using this to run in a Python that doesn't support it. Fixes #51422, fixes #54706. This doesn't have any unit tests, as a) it's relatively simple, and b) due to how we run in the same process in the tests, there is no socket to reconnect to, so we can't actually exercise this code --- .../airflow/providers/standard/utils/python_virtualenv.py | 2 +- .../standard/utils/python_virtualenv_script.jinja2 | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/providers/standard/src/airflow/providers/standard/utils/python_virtualenv.py b/providers/standard/src/airflow/providers/standard/utils/python_virtualenv.py index ee71f33a560..891b3e0bce3 100644 --- a/providers/standard/src/airflow/providers/standard/utils/python_virtualenv.py +++ b/providers/standard/src/airflow/providers/standard/utils/python_virtualenv.py @@ -150,7 +150,7 @@ def _execute_in_subprocess(cmd: list[str], cwd: str | None = None, env: dict[str stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0, - close_fds=True, + close_fds=False, cwd=cwd, env=env, ) as proc: diff --git a/providers/standard/src/airflow/providers/standard/utils/python_virtualenv_script.jinja2 b/providers/standard/src/airflow/providers/standard/utils/python_virtualenv_script.jinja2 index cb4b738138f..6c0c69d14b5 100644 --- a/providers/standard/src/airflow/providers/standard/utils/python_virtualenv_script.jinja2 +++ b/providers/standard/src/airflow/providers/standard/utils/python_virtualenv_script.jinja2 @@ -40,6 +40,17 @@ if sys.version_info >= (3,6): pass {% endif %} +try: + from airflow.sdk.execution_time import task_runner +except ModuleNotFoundError: + pass +else: + {#- We are in an Airflow 3.x env, try and set up supervisor comms so virtual env can still access tasks etc! #} + reinit_supervisor_comms = getattr(task_runner, "reinit_supervisor_comms", None) + os.environ["PUDB_TTY"] = "/dev/pts/2" + if reinit_supervisor_comms: + reinit_supervisor_comms() + # Script {{ python_callable_source }} @@ -49,12 +60,10 @@ if sys.version_info >= (3,6): import types {{ modified_dag_module_name }} = types.ModuleType("{{ modified_dag_module_name }}") - {{ modified_dag_module_name }}.{{ python_callable }} = {{ python_callable }} - sys.modules["{{modified_dag_module_name}}"] = {{modified_dag_module_name}} -{% endif%} +{%- endif -%} {% if op_args or op_kwargs %} with open(sys.argv[1], "rb") as file:
