This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-3-test by this push:
     new fff35ce6a4b [v3-3-test] Fix static checks randomly failing with 
"PYTHONWARNINGS not set" (#72226) (#72232)
fff35ce6a4b is described below

commit fff35ce6a4b972c7f8d27c7d203a0535cb05c7ac
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 28 21:57:50 2026 +0200

    [v3-3-test] Fix static checks randomly failing with "PYTHONWARNINGS not 
set" (#72226) (#72232)
    
    The generated docker-compose env file lists the variables Compose forwards
    into the container, and every Breeze invocation rewrites it from its own
    environment. prek runs Breeze-backed hooks concurrently and only the
    provider.yaml and template-fields checks ask for PYTHONWARNINGS, so any
    other hook regenerating the file between that write and `docker compose
    run` took the variable away again — leaving contributors with static check
    failures that had nothing to do with their change and passed on a rerun.
    (cherry picked from commit 964407f66ca7ce07d231add5fdfcb12263b9d0d2)
    
    Co-authored-by: rjgoyln <[email protected]>
---
 .../src/airflow_breeze/params/shell_params.py      |  9 ++++++--
 dev/breeze/tests/test_shell_params.py              | 25 ++++++++++++++++++++++
 scripts/ci/docker-compose/base.yml                 |  3 +++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/params/shell_params.py 
b/dev/breeze/src/airflow_breeze/params/shell_params.py
index f900fb079f2..89cdbbcb113 100644
--- a/dev/breeze/src/airflow_breeze/params/shell_params.py
+++ b/dev/breeze/src/airflow_breeze/params/shell_params.py
@@ -571,7 +571,9 @@ services:
         separately with different test types.
 
         This is the only place where you need to add environment variables if 
you want to pass them to
-        docker or docker-compose.
+        docker or docker-compose. Variables that only some of the invocations 
set are the exception -
+        they are listed in the ``environment`` section of 
``scripts/ci/docker-compose/base.yml``
+        instead, see _generate_env_for_docker_compose_file_if_needed for why.
 
         :return: dictionary of env variables to use for docker-compose and 
docker command
         """
@@ -689,7 +691,6 @@ services:
         _set_var(_env, "PROVIDERS_CONSTRAINTS_REFERENCE", 
self.providers_constraints_reference)
         _set_var(_env, "PROVIDERS_SKIP_CONSTRAINTS", 
self.providers_skip_constraints)
         _set_var(_env, "PYTHONDONTWRITEBYTECODE", "true")
-        _set_var(_env, "PYTHONWARNINGS", None, None)
         _set_var(_env, "PYTHON_MAJOR_MINOR_VERSION", self.python)
         _set_var(_env, "QUIET", self.quiet)
         _set_var(_env, "REDIS_HOST_PORT", None, REDIS_HOST_PORT)
@@ -778,6 +779,10 @@ services:
         one place (above env_variables_for_docker_commands method). So we need 
to regenerate the env
         files automatically when new variable is added to the list or removed.
 
+        The keys must not depend on the ambient environment though. All 
concurrent breeze invocations
+        share these files, so a key that only some of them contribute is taken 
away again from the
+        containers of the others as soon as another invocation regenerates the 
files.
+
         Docker-Compose based tests can start in parallel, so we want to make 
sure we generate it once
         per invocation of breeze command otherwise there could be nasty race 
condition that
         the file would be empty while another compose tries to use it when 
starting.
diff --git a/dev/breeze/tests/test_shell_params.py 
b/dev/breeze/tests/test_shell_params.py
index ffc0dc56e5b..0d67d51e017 100644
--- a/dev/breeze/tests/test_shell_params.py
+++ b/dev/breeze/tests/test_shell_params.py
@@ -20,10 +20,12 @@ from __future__ import annotations
 from unittest.mock import patch
 
 import pytest
+import yaml
 from rich.console import Console
 
 from airflow_breeze.branch_defaults import AIRFLOW_BRANCH
 from airflow_breeze.params.shell_params import ShellParams
+from airflow_breeze.utils.path_utils import SCRIPTS_CI_DOCKER_COMPOSE_BASE_PATH
 
 console = Console(width=400, color_system="standard")
 
@@ -193,3 +195,26 @@ def test_shell_params_to_env_var_conversion(
                 console.print(env_vars)
                 error = True
         assert not error, "Some values are not as expected."
+
+
+def 
test_generated_env_files_do_not_change_when_pythonwarnings_is_set(tmp_path, 
monkeypatch):
+    docker_env_path = tmp_path / "_generated_docker.env"
+    compose_env_path = tmp_path / "_generated_docker_compose.env"
+    with (
+        patch("airflow_breeze.params.shell_params.GENERATED_DOCKER_ENV_PATH", 
docker_env_path),
+        
patch("airflow_breeze.params.shell_params.GENERATED_DOCKER_COMPOSE_ENV_PATH", 
compose_env_path),
+        patch("airflow_breeze.params.shell_params.GENERATED_DOCKER_LOCK_PATH", 
tmp_path / "_generated.lock"),
+    ):
+        monkeypatch.delenv("PYTHONWARNINGS", raising=False)
+        _ = ShellParams().env_variables_for_docker_commands
+        docker_env = docker_env_path.read_text()
+        compose_env = compose_env_path.read_text()
+        monkeypatch.setenv("PYTHONWARNINGS", "default")
+        _ = ShellParams().env_variables_for_docker_commands
+        assert docker_env_path.read_text() == docker_env
+        assert compose_env_path.read_text() == compose_env
+
+
+def test_pythonwarnings_is_forwarded_by_the_compose_base_file():
+    base_compose_file = 
yaml.safe_load(SCRIPTS_CI_DOCKER_COMPOSE_BASE_PATH.read_text())
+    assert "PYTHONWARNINGS" in 
base_compose_file["services"]["airflow"]["environment"]
diff --git a/scripts/ci/docker-compose/base.yml 
b/scripts/ci/docker-compose/base.yml
index abbb96e9654..b9a8fda2cb9 100644
--- a/scripts/ci/docker-compose/base.yml
+++ b/scripts/ci/docker-compose/base.yml
@@ -23,6 +23,9 @@ services:
       - USER=root
       - ADDITIONAL_PATH=~/.local/bin
       - KUBECONFIG=/files/.kube/config
+      # Only some breeze invocations set it, so it cannot go through the shared
+      # _generated_docker_compose.env - see 
ShellParams.env_variables_for_docker_commands.
+      - PYTHONWARNINGS
     env_file:
       - _generated_docker_compose.env
     volumes:

Reply via email to