From ea95108c94572a523ee606489e1aea43f7bdf62c Mon Sep 17 00:00:00 2001 From: Saiteja Bandaru Date: Wed, 26 Aug 2026 23:52:55 +0200 Subject: [PATCH] Allow Variable.get_variable_from_secrets to reuse session This adds an optional keyword-only `session=None` argument to `Variable.get_variable_from_secrets` and forwards it to `MetastoreBackend`. This allows callers running under `prohibit_commit` (like the scheduler) to resolve variables from the secrets chain without tripping unexpected commits via `@provide_session`, enabling deduplication of secrets backend iteration loops in `_process_dagrun_deadline_alerts`.\n\nCloses: #71801 --- airflow-core/src/airflow/models/variable.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/airflow-core/src/airflow/models/variable.py b/airflow-core/src/airflow/models/variable.py index b06e73cd5f50a..96c591b8b24bd 100644 --- a/airflow-core/src/airflow/models/variable.py +++ b/airflow-core/src/airflow/models/variable.py @@ -459,7 +459,7 @@ def check_for_write_conflict(key: str) -> None: return None @staticmethod - def get_variable_from_secrets(key: str, team_name: str | None = None) -> str | None: + def get_variable_from_secrets(key: str, team_name: str | None = None, *, session: Session | None = None) -> str | None: """ Get Airflow Variable by iterating over all Secret Backends. @@ -480,8 +480,12 @@ def get_variable_from_secrets(key: str, team_name: str | None = None) -> str | N # iterate over backends if not in cache (or expired) for secrets_backend in ensure_secrets_loaded(): try: + kwargs = {"team_name": team_name, "key": key} + if type(secrets_backend).__name__ == "MetastoreBackend" and session is not None: + kwargs["session"] = session + var_val = call_secrets_backend_method( - secrets_backend.get_variable, team_name=team_name, key=key + secrets_backend.get_variable, **kwargs ) if var_val is not None: break