diff --git a/UPDATING.md b/UPDATING.md index 8f8c8c7d31c71..9f681475b718b 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -22,6 +22,9 @@ This file documents any backwards-incompatible changes in Superset and assists people when migrating to a new version. ## Next +* [9109](https://github.com/apache/incubator-superset/pull/9109): Expire `filter_immune_slices` and +`filter_immune_filter_fields` to favor dashboard scoped filter metadata `filter_scopes`. + * [9046](https://github.com/apache/incubator-superset/pull/9046): Replaces `can_only_access_owned_queries` by `all_query_access` favoring a white list approach. Since a new permission is introduced use `superset init` to create and associate it by default to the `Admin` role. Note that, by default, all non `Admin` users will diff --git a/superset/migrations/versions/3325d4caccc8_dashboard_scoped_filters.py b/superset/migrations/versions/3325d4caccc8_dashboard_scoped_filters.py index 8c26173ae9133..d3a96427cd582 100644 --- a/superset/migrations/versions/3325d4caccc8_dashboard_scoped_filters.py +++ b/superset/migrations/versions/3325d4caccc8_dashboard_scoped_filters.py @@ -78,7 +78,6 @@ def upgrade(): if "filter_scopes" in json_metadata: continue - filter_scopes = {} filters = [ slice for slice in dashboard.slices if slice.viz_type == "filter_box" ] @@ -86,18 +85,20 @@ def upgrade(): # if dashboard has filter_box if filters: filter_scopes = convert_filter_scopes(json_metadata, filters) - - json_metadata.pop("filter_immune_slices", None) - json_metadata.pop("filter_immune_slice_fields", None) - if filter_scopes: json_metadata["filter_scopes"] = filter_scopes logging.info( f"Adding filter_scopes for dashboard {dashboard.id}: {json.dumps(filter_scopes)}" ) + + json_metadata.pop("filter_immune_slices", None) + json_metadata.pop("filter_immune_slice_fields", None) + if json_metadata: dashboard.json_metadata = json.dumps( json_metadata, indent=None, separators=(",", ":"), sort_keys=True ) + else: + dashboard.json_metadata = None session.merge(dashboard) except Exception as e: diff --git a/superset/utils/dashboard_filter_scopes_converter.py b/superset/utils/dashboard_filter_scopes_converter.py index 8d07644a3003f..7fff9dd1c5e29 100644 --- a/superset/utils/dashboard_filter_scopes_converter.py +++ b/superset/utils/dashboard_filter_scopes_converter.py @@ -16,6 +16,7 @@ # under the License. import json import logging +from collections import defaultdict from typing import Dict, List from superset.models.slice import Slice @@ -26,13 +27,11 @@ def convert_filter_scopes(json_metadata: Dict, filters: List[Slice]): filter_scopes = {} immuned_by_id: List[int] = json_metadata.get("filter_immune_slices") or [] - immuned_by_column: Dict = {} + immuned_by_column: Dict = defaultdict(list) for slice_id, columns in json_metadata.get( "filter_immune_slice_fields", {} ).items(): for column in columns: - if immuned_by_column.get(column, None) is None: - immuned_by_column[column] = [] immuned_by_column[column].append(int(slice_id)) def add_filter_scope(filter_field, filter_id):