Skip to content

Commit

Permalink
refactor(feature_flags configurations): remove redundant additional c…
Browse files Browse the repository at this point in the history
…onfiguration for default vales (apache#15425)
  • Loading branch information
ofekisr authored Jun 28, 2021
1 parent d8a1acf commit 486b8d9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ export enum FeatureFlag {
}
```

`superset/config.py` contains `DEFAULT_FEATURE_FLAGS` which will be overwritten by
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
in combined feature flags of `{ 'FOO': True, 'BAR': True, 'BAZ': True }`.
`superset/config.py` contains `FEATURE_FLAGS` with their default values which will be
overwritten by
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`.

Expand Down
2 changes: 1 addition & 1 deletion superset/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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_func = config.GET_FEATURE_FLAGS_FUNC
if feature_flags_func:
Expand Down
14 changes: 3 additions & 11 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,8 @@ def _try_json_readsha( # pylint: disable=unused-argument
# ---------------------------------------------------
# Feature flags
# ---------------------------------------------------
# Feature flags that are set by default go here. Their values can be
# overwritten by those specified under FEATURE_FLAGS in superset_config.py
# 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] = {
# Feature flags that are set by default go here.
FEATURE_FLAGS: Dict[str, bool] = {
# allow dashboard to use sub-domains to send chart request
# you also need ENABLE_CORS and
# SUPERSET_WEBSERVER_DOMAINS for list of domains
Expand Down Expand Up @@ -394,19 +390,15 @@ def _try_json_readsha( # pylint: disable=unused-argument
}

# 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)
for k, v in os.environ.items()
if re.search(r"^SUPERSET_FEATURE_\w+", k)
}
)

# This is merely a default.
FEATURE_FLAGS: Dict[str, bool] = {}

# 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
# flags passed to the function is a deepcopy of the dict in the config,
# and can therefore be mutated without side-effect
Expand Down
3 changes: 1 addition & 2 deletions superset/utils/feature_flag_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def __init__(self) -> None:

def init_app(self, app: Flask) -> None:
self._get_feature_flags_func = app.config["GET_FEATURE_FLAGS_FUNC"]
self._feature_flags = app.config["DEFAULT_FEATURE_FLAGS"]
self._feature_flags.update(app.config["FEATURE_FLAGS"])
self._feature_flags = app.config["FEATURE_FLAGS"].copy()

def get_feature_flags(self) -> Dict[str, Any]:
if self._get_feature_flags_func:
Expand Down
8 changes: 4 additions & 4 deletions tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_export_datasources_original(app_context, fs):

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@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):
"""
Expand All @@ -107,7 +107,7 @@ def test_export_dashboards_versioned_export(app_context, fs):

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@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):
"""
Expand All @@ -131,7 +131,7 @@ def test_export_datasources_versioned_export(app_context, fs):


@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")
def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs):
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte


@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")
def test_import_datasets_versioned_export(import_datasets_command, app_context, fs):
Expand Down

0 comments on commit 486b8d9

Please sign in to comment.