From 3a3cda3e746687c3344d5791f28578298f67b943 Mon Sep 17 00:00:00 2001 From: JD Bertron Date: Fri, 26 Apr 2019 11:21:21 -0600 Subject: [PATCH 1/2] Fix migration metadata lock on ab_view_menu This fix is to make sure the scoped session created by the AppBuilder init code (that creates a bunch of roles and permissions) will be released and committed when the AppBuidler init code goes out of scope. Without running in a context, the code leaves the session open with a lock on ab_view_menu metadata, which prevents migration cefabc8f7d38_increase_size_of_name_column_in_ab_view from running an ALTER on that table. modified: superset/__init__.py --- superset/__init__.py | 51 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/superset/__init__.py b/superset/__init__.py index 7d0df26e039e7..5ffea4145e8a0 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -196,40 +196,41 @@ def index(self): not FAB's security manager. See [4565] in UPDATING.md""") -appbuilder = AppBuilder( - app, - db.session, - base_template='superset/base.html', - indexview=MyIndexView, - security_manager_class=custom_sm, - update_perms=get_update_perms_flag(), -) +with app.app_context(): + appbuilder = AppBuilder( + app, + db.session, + base_template='superset/base.html', + indexview=MyIndexView, + security_manager_class=custom_sm, + update_perms=get_update_perms_flag(), + ) -security_manager = appbuilder.sm + security_manager = appbuilder.sm -results_backend = app.config.get('RESULTS_BACKEND') + results_backend = app.config.get('RESULTS_BACKEND') -# Merge user defined feature flags with default feature flags -_feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS') or {} -_feature_flags.update(app.config.get('FEATURE_FLAGS') or {}) + # Merge user defined feature flags with default feature flags + _feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS') or {} + _feature_flags.update(app.config.get('FEATURE_FLAGS') or {}) -def get_feature_flags(): - GET_FEATURE_FLAGS_FUNC = app.config.get('GET_FEATURE_FLAGS_FUNC') - if GET_FEATURE_FLAGS_FUNC: - return GET_FEATURE_FLAGS_FUNC(deepcopy(_feature_flags)) - return _feature_flags + def get_feature_flags(): + GET_FEATURE_FLAGS_FUNC = app.config.get('GET_FEATURE_FLAGS_FUNC') + if GET_FEATURE_FLAGS_FUNC: + return GET_FEATURE_FLAGS_FUNC(deepcopy(_feature_flags)) + return _feature_flags -def is_feature_enabled(feature): - """Utility function for checking whether a feature is turned on""" - return get_feature_flags().get(feature) + def is_feature_enabled(feature): + """Utility function for checking whether a feature is turned on""" + return get_feature_flags().get(feature) -# Registering sources -module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP') -module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP')) -ConnectorRegistry.register_sources(module_datasource_map) + # Registering sources + module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP') + module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP')) + ConnectorRegistry.register_sources(module_datasource_map) # Flask-Compress if conf.get('ENABLE_FLASK_COMPRESS'): From fb15aa91a2b175b7f46a396bab7c881dafe7ae19 Mon Sep 17 00:00:00 2001 From: "J.D. Bertron" Date: Thu, 2 May 2019 16:35:29 -0600 Subject: [PATCH 2/2] Update __init__.py per code review comment. --- superset/__init__.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/superset/__init__.py b/superset/__init__.py index 5ffea4145e8a0..853dd567e81c7 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -206,31 +206,31 @@ def index(self): update_perms=get_update_perms_flag(), ) - security_manager = appbuilder.sm +security_manager = appbuilder.sm - results_backend = app.config.get('RESULTS_BACKEND') +results_backend = app.config.get('RESULTS_BACKEND') - # Merge user defined feature flags with default feature flags - _feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS') or {} - _feature_flags.update(app.config.get('FEATURE_FLAGS') or {}) +# Merge user defined feature flags with default feature flags +_feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS') or {} +_feature_flags.update(app.config.get('FEATURE_FLAGS') or {}) - def get_feature_flags(): - GET_FEATURE_FLAGS_FUNC = app.config.get('GET_FEATURE_FLAGS_FUNC') - if GET_FEATURE_FLAGS_FUNC: - return GET_FEATURE_FLAGS_FUNC(deepcopy(_feature_flags)) - return _feature_flags +def get_feature_flags(): + GET_FEATURE_FLAGS_FUNC = app.config.get('GET_FEATURE_FLAGS_FUNC') + if GET_FEATURE_FLAGS_FUNC: + return GET_FEATURE_FLAGS_FUNC(deepcopy(_feature_flags)) + return _feature_flags - def is_feature_enabled(feature): - """Utility function for checking whether a feature is turned on""" - return get_feature_flags().get(feature) +def is_feature_enabled(feature): + """Utility function for checking whether a feature is turned on""" + return get_feature_flags().get(feature) - # Registering sources - module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP') - module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP')) - ConnectorRegistry.register_sources(module_datasource_map) +# Registering sources +module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP') +module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP')) +ConnectorRegistry.register_sources(module_datasource_map) # Flask-Compress if conf.get('ENABLE_FLASK_COMPRESS'):