You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2023/03/07 20:46:15 UTC

[airflow] 02/04: Fix import cycle starting from airflow/__main__.py (#29523)

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

ephraimanierobi pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit dd1673d9be635cda2b3f39a0ffe2ef6a06b8b54f
Author: Niko Oliveira <on...@amazon.com>
AuthorDate: Tue Feb 14 13:24:15 2023 -0800

    Fix import cycle starting from airflow/__main__.py (#29523)
    
    (cherry picked from commit 81f07274b9cd9369a1024eb8b0ad5ee6058202f0)
---
 airflow/__main__.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/airflow/__main__.py b/airflow/__main__.py
index 6114534e1c..b355a6a52d 100644
--- a/airflow/__main__.py
+++ b/airflow/__main__.py
@@ -24,12 +24,21 @@ import os
 
 import argcomplete
 
+# The configuration module initializes and validates the conf object as a side effect the first
+# time it is imported. If it is not imported before importing the settings module, the conf
+# object will then be initted/validated as a side effect of it being imported in settings,
+# however this can cause issues since those modules are very tightly coupled and can
+# very easily cause import cycles in the conf init/validate code (since downstream code from
+# those functions likely import settings).
+# Therefore importing configuration early (as the first airflow import) avoids
+# any possible import cycles with settings downstream.
+from airflow import configuration
 from airflow.cli import cli_parser
-from airflow.configuration import conf
 
 
 def main():
-    """Main executable function"""
+    """Main executable function."""
+    conf = configuration.conf
     if conf.get("core", "security") == "kerberos":
         os.environ["KRB5CCNAME"] = conf.get("kerberos", "ccache")
         os.environ["KRB5_KTNAME"] = conf.get("kerberos", "keytab")