diff --git a/airflow-core/src/airflow/dag_processing/manager.py b/airflow-core/src/airflow/dag_processing/manager.py index ff6ff81ab1ea2..232c0d978acff 100644 --- a/airflow-core/src/airflow/dag_processing/manager.py +++ b/airflow-core/src/airflow/dag_processing/manager.py @@ -251,6 +251,16 @@ def run(self): By processing them in separate processes, we can get parallelism and isolation from potentially harmful user code. """ + # TODO: Temporary until AIP-92 removes DB access from DagProcessorManager. + # The manager needs MetastoreBackend to retrieve connections from the database + # during bundle initialization (e.g., GitDagBundle.__init__ → GitHook needs git credentials). + # This marks the manager as "server" context so ensure_secrets_backend_loaded() provides + # MetastoreBackend instead of falling back to EnvironmentVariablesBackend only. + # Child parser processes explicitly override this by setting _AIRFLOW_PROCESS_CONTEXT=client + # in _parse_file_entrypoint() to prevent inheriting server privileges. + # Related: https://github.com/apache/airflow/pull/57459 + os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server" + self.register_exit_signals() self.log.info("Processing files using up to %s processes at a time ", self._parallelism) diff --git a/airflow-core/src/airflow/dag_processing/processor.py b/airflow-core/src/airflow/dag_processing/processor.py index bf937eac53ff5..122b2fd0768a8 100644 --- a/airflow-core/src/airflow/dag_processing/processor.py +++ b/airflow-core/src/airflow/dag_processing/processor.py @@ -174,6 +174,10 @@ def _pre_import_airflow_modules(file_path: str, log: FilteringBoundLogger) -> No def _parse_file_entrypoint(): + # Mark as client-side (runs user DAG code) + # Prevents inheriting server context from parent DagProcessorManager + os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "client" + import structlog from airflow.sdk.execution_time import comms, task_runner