From 9fb9101a6fb4c2676e102ea436910b244c51f270 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 26 May 2021 17:13:42 +0200 Subject: [PATCH] Fixes problem where conf variable was used before initialization There was a problem that when we initialized configuration, we've run validate() which - among others - checkd if the connection is an `sqlite` but when the SQLAlchemy connection was not configured via variable but via secret manager, it has fallen back to secret_backend, which should be configured via conf and initialized. The problem is that the "conf" object is not yet created, because the "validate()" method has not finished yet and "initialize_configuration" has not yet returned. This led to snake eating its own tail. This PR defers the validate() method to after secret backends have been initialized. The effect of it is that secret backends might be initialized with configuration that is not valid, but there are no real negative consequences of this. Fixes: #16079 Fixes: #15685 starting --- airflow/configuration.py | 4 +--- tests/www/views/test_views.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index 5dd13fd3dfedb..458d6e59d67ea 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -873,9 +873,6 @@ def initialize_config(): log.info('Creating new FAB webserver config file in: %s', WEBSERVER_CONFIG) shutil.copy(_default_config_file_path('default_webserver_config.py'), WEBSERVER_CONFIG) - - conf.validate() - return conf @@ -1114,6 +1111,7 @@ def __getattr__(name): conf = initialize_config() secrets_backend_list = initialize_secrets_backends() +conf.validate() PY37 = sys.version_info >= (3, 7) diff --git a/tests/www/views/test_views.py b/tests/www/views/test_views.py index 98623da735f7a..bac6feca9016d 100644 --- a/tests/www/views/test_views.py +++ b/tests/www/views/test_views.py @@ -44,7 +44,8 @@ def test_configuration_do_not_expose_config(admin_client): @mock.patch.dict(os.environ, {"AIRFLOW__CORE__UNIT_TEST_MODE": "False"}) def test_configuration_expose_config(admin_client): # make sure config is initialized (without unit test mote) - initialize_config() + conf = initialize_config() + conf.validate() with conf_vars({('webserver', 'expose_config'): 'True'}): resp = admin_client.get('configuration', follow_redirects=True) check_content_in_response(['Airflow Configuration', 'Running Configuration'], resp)