Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions airflow-core/src/airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@

SIMPLE_LOG_FORMAT = conf.get("logging", "simple_log_format")

SQL_ALCHEMY_CONN: str | None = None
SQL_ALCHEMY_CONN_ASYNC: str | None = None
PLUGINS_FOLDER: str | None = None
DAGS_FOLDER: str = os.path.expanduser(conf.get_mandatory_value("core", "DAGS_FOLDER"))

engine: Engine | None = None
Session: scoped_session | None = None
# NonScopedSession creates global sessions and is not safe to use in multi-threaded environment without
Expand Down Expand Up @@ -247,24 +242,6 @@ def _get_async_conn_uri_from_sync(sync_uri):
return sync_uri


def configure_vars():
"""Configure Global Variables from airflow.cfg."""
global SQL_ALCHEMY_CONN
global SQL_ALCHEMY_CONN_ASYNC
global DAGS_FOLDER
global PLUGINS_FOLDER

SQL_ALCHEMY_CONN = conf.get("database", "sql_alchemy_conn")
if conf.has_option("database", "sql_alchemy_conn_async"):
SQL_ALCHEMY_CONN_ASYNC = conf.get("database", "sql_alchemy_conn_async")
else:
SQL_ALCHEMY_CONN_ASYNC = _get_async_conn_uri_from_sync(sync_uri=SQL_ALCHEMY_CONN)

DAGS_FOLDER = os.path.expanduser(conf.get("core", "DAGS_FOLDER"))

PLUGINS_FOLDER = conf.get("core", "plugins_folder", fallback=os.path.join(AIRFLOW_HOME, "plugins"))


def _run_openlineage_runtime_check():
"""
Ensure compatibility of OpenLineage provider package and Airflow version.
Expand Down Expand Up @@ -720,9 +697,19 @@ def import_local_settings():
log.info("Loaded airflow_local_settings from %s .", airflow_local_settings.__file__)


SQL_ALCHEMY_CONN: str = conf.get("database", "sql_alchemy_conn")
SQL_ALCHEMY_CONN_ASYNC: str = (
conf.get("database", "sql_alchemy_conn_async")
if conf.has_option("database", "sql_alchemy_conn_async")
else _get_async_conn_uri_from_sync(sync_uri=SQL_ALCHEMY_CONN)
)

PLUGINS_FOLDER = conf.get("core", "plugins_folder", fallback=os.path.join(AIRFLOW_HOME, "plugins"))
DAGS_FOLDER: str = os.path.expanduser(conf.get_mandatory_value("core", "DAGS_FOLDER"))


def initialize():
"""Initialize Airflow with all the settings from this file."""
configure_vars()
prepare_syspath_for_config_and_plugins()
policy_mgr = get_policy_plugin_manager()
# Load policy plugins _before_ importing airflow_local_settings, as Pluggy uses LIFO and we want anything
Expand Down
10 changes: 4 additions & 6 deletions devel-common/src/tests_common/test_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def conf_vars(overrides):
"""Automatically detects which config modules are loaded (Core, SDK, or both) and updates them accordingly temporarily."""
import sys

from airflow import settings

configs = []
if "airflow.configuration" in sys.modules:
from airflow.configuration import conf
Expand All @@ -54,8 +52,8 @@ def conf_vars(overrides):
elif conf.has_section(section) and conf.has_option(section, key):
conf.remove_option(section, key)

if "airflow.configuration" in sys.modules:
settings.configure_vars()
if "airflow.configuration" in sys.modules and "airflow.settings" in sys.modules:
del sys.modules["airflow.settings"]

try:
yield
Expand All @@ -72,8 +70,8 @@ def conf_vars(overrides):
for env, value in original_env_vars.items():
os.environ[env] = value

if "airflow.configuration" in sys.modules:
settings.configure_vars()
if "airflow.configuration" in sys.modules and "airflow.settings" in sys.modules:
del sys.modules["airflow.settings"]


@contextlib.contextmanager
Expand Down
Loading