refactor(feature_flags configurations): remove redundant additional configuration for default vales (#15425)

This commit is contained in:
ofekisr 2021-06-28 16:30:13 +03:00 committed by GitHub
parent d8a1acffde
commit 486b8d911f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 21 deletions

View File

@ -605,9 +605,9 @@ export enum FeatureFlag {
} }
``` ```
`superset/config.py` contains `DEFAULT_FEATURE_FLAGS` which will be overwritten by `superset/config.py` contains `FEATURE_FLAGS` with their default values which will be
those specified under FEATURE_FLAGS in `superset_config.py`. For example, `DEFAULT_FEATURE_FLAGS = { 'FOO': True, 'BAR': False }` in `superset/config.py` and `FEATURE_FLAGS = { 'BAR': True, 'BAZ': True }` in `superset_config.py` will result overwritten by
in combined feature flags of `{ 'FOO': True, 'BAR': True, 'BAZ': True }`. those specified under FEATURE_FLAGS in `superset_config.py`.
The current status of the usability of each flag (stable vs testing, etc) can be found in `RESOURCES/FEATURE_FLAGS.md`. The current status of the usability of each flag (stable vs testing, etc) can be found in `RESOURCES/FEATURE_FLAGS.md`.

View File

@ -42,7 +42,7 @@ from superset.utils.urls import get_url_path
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
feature_flags = config.DEFAULT_FEATURE_FLAGS.copy() feature_flags = config.FEATURE_FLAGS.copy()
feature_flags.update(config.FEATURE_FLAGS) feature_flags.update(config.FEATURE_FLAGS)
feature_flags_func = config.GET_FEATURE_FLAGS_FUNC feature_flags_func = config.GET_FEATURE_FLAGS_FUNC
if feature_flags_func: if feature_flags_func:

View File

@ -310,12 +310,8 @@ LANGUAGES = {}
# --------------------------------------------------- # ---------------------------------------------------
# Feature flags # Feature flags
# --------------------------------------------------- # ---------------------------------------------------
# Feature flags that are set by default go here. Their values can be # Feature flags that are set by default go here.
# overwritten by those specified under FEATURE_FLAGS in superset_config.py FEATURE_FLAGS: Dict[str, bool] = {
# For example, DEFAULT_FEATURE_FLAGS = { 'FOO': True, 'BAR': False } here
# and FEATURE_FLAGS = { 'BAR': True, 'BAZ': True } in superset_config.py
# will result in combined feature flags of { 'FOO': True, 'BAR': True, 'BAZ': True }
DEFAULT_FEATURE_FLAGS: Dict[str, bool] = {
# allow dashboard to use sub-domains to send chart request # allow dashboard to use sub-domains to send chart request
# you also need ENABLE_CORS and # you also need ENABLE_CORS and
# SUPERSET_WEBSERVER_DOMAINS for list of domains # SUPERSET_WEBSERVER_DOMAINS for list of domains
@ -394,7 +390,7 @@ DEFAULT_FEATURE_FLAGS: Dict[str, bool] = {
} }
# Feature flags may also be set via 'SUPERSET_FEATURE_' prefixed environment vars. # Feature flags may also be set via 'SUPERSET_FEATURE_' prefixed environment vars.
DEFAULT_FEATURE_FLAGS.update( FEATURE_FLAGS.update(
{ {
k[len("SUPERSET_FEATURE_") :]: parse_boolean_string(v) k[len("SUPERSET_FEATURE_") :]: parse_boolean_string(v)
for k, v in os.environ.items() for k, v in os.environ.items()
@ -402,11 +398,7 @@ DEFAULT_FEATURE_FLAGS.update(
} }
) )
# This is merely a default.
FEATURE_FLAGS: Dict[str, bool] = {}
# A function that receives a dict of all feature flags # A function that receives a dict of all feature flags
# (DEFAULT_FEATURE_FLAGS merged with FEATURE_FLAGS)
# can alter it, and returns a similar dict. Note the dict of feature # can alter it, and returns a similar dict. Note the dict of feature
# flags passed to the function is a deepcopy of the dict in the config, # flags passed to the function is a deepcopy of the dict in the config,
# and can therefore be mutated without side-effect # and can therefore be mutated without side-effect

View File

@ -28,8 +28,7 @@ class FeatureFlagManager:
def init_app(self, app: Flask) -> None: def init_app(self, app: Flask) -> None:
self._get_feature_flags_func = app.config["GET_FEATURE_FLAGS_FUNC"] self._get_feature_flags_func = app.config["GET_FEATURE_FLAGS_FUNC"]
self._feature_flags = app.config["DEFAULT_FEATURE_FLAGS"] self._feature_flags = app.config["FEATURE_FLAGS"].copy()
self._feature_flags.update(app.config["FEATURE_FLAGS"])
def get_feature_flags(self) -> Dict[str, Any]: def get_feature_flags(self) -> Dict[str, Any]:
if self._get_feature_flags_func: if self._get_feature_flags_func:

View File

@ -82,7 +82,7 @@ def test_export_datasources_original(app_context, fs):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict( @mock.patch.dict(
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True "superset.config.FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
) )
def test_export_dashboards_versioned_export(app_context, fs): def test_export_dashboards_versioned_export(app_context, fs):
""" """
@ -107,7 +107,7 @@ def test_export_dashboards_versioned_export(app_context, fs):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict( @mock.patch.dict(
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True "superset.config.FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
) )
def test_export_datasources_versioned_export(app_context, fs): def test_export_datasources_versioned_export(app_context, fs):
""" """
@ -131,7 +131,7 @@ def test_export_datasources_versioned_export(app_context, fs):
@mock.patch.dict( @mock.patch.dict(
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True "superset.config.FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
) )
@mock.patch("superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand") @mock.patch("superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand")
def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs): def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs):
@ -170,7 +170,7 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte
@mock.patch.dict( @mock.patch.dict(
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True "superset.config.FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
) )
@mock.patch("superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand") @mock.patch("superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand")
def test_import_datasets_versioned_export(import_datasets_command, app_context, fs): def test_import_datasets_versioned_export(import_datasets_command, app_context, fs):