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

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

commit 9a3fb628c864788d671fbe79cf15337fb18aa970
Author: Jarek Potiuk <[email protected]>
AuthorDate: Thu May 27 18:37:56 2021 +0200

    Fixes problem where conf variable was used before initialization (#16088)
    
    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
    
    (cherry picked from commit 65519ab83ddf4bd6fc30c435b5bfccefcb14d596)
---
 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 4420dda..53e76a6 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 @@ WEBSERVER_CONFIG = ''  # Set by initialize_config
 
 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 738bf26..eac1e5e 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)

Reply via email to