Skip to content

Commit

Permalink
Fixes problem where conf variable was used before initialization (apa…
Browse files Browse the repository at this point in the history
…che#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: apache#16079
Fixes: apache#15685

starting

(cherry picked from commit 65519ab)
  • Loading branch information
potiuk authored and jhtimmins committed Jun 3, 2021
1 parent 3c169fb commit 194762f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions airflow/configuration.py
Expand Up @@ -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


Expand Down Expand Up @@ -1114,6 +1111,7 @@ def __getattr__(name):

conf = initialize_config()
secrets_backend_list = initialize_secrets_backends()
conf.validate()


PY37 = sys.version_info >= (3, 7)
Expand Down
3 changes: 2 additions & 1 deletion tests/www/views/test_views.py
Expand Up @@ -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)
Expand Down

0 comments on commit 194762f

Please sign in to comment.