diff --git a/superset/dashboards/commands/importers/v1/utils.py b/superset/dashboards/commands/importers/v1/utils.py index c3dee1578e30..a8dbc46c0be9 100644 --- a/superset/dashboards/commands/importers/v1/utils.py +++ b/superset/dashboards/commands/importers/v1/utils.py @@ -134,6 +134,12 @@ def update_id_refs( # pylint: disable=too-many-locals if dataset_uuid: target["datasetId"] = dataset_info[dataset_uuid]["datasource_id"] + scope_excluded = native_filter.get("scope", {}).get("excluded", []) + if scope_excluded: + native_filter["scope"]["excluded"] = [ + id_map[old_id] for old_id in scope_excluded + ] + return fixed diff --git a/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py index d0ee3157f6b2..320482a0e394 100644 --- a/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py +++ b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py @@ -49,8 +49,8 @@ def test_update_id_refs_immune_missing( # pylint: disable=invalid-name "101": {"filter_name": {"immune": [102, 103]}}, "104": {"filter_name": {"immune": [102, 103]}}, }, + "native_filter_configuration": [], }, - "native_filter_configuration": [], } chart_ids = {"uuid1": 1, "uuid2": 2} dataset_info: Dict[str, Dict[str, Any]] = {} # not used @@ -69,6 +69,49 @@ def test_update_id_refs_immune_missing( # pylint: disable=invalid-name "type": "CHART", }, }, - "metadata": {"filter_scopes": {"1": {"filter_name": {"immune": [2]}}}}, - "native_filter_configuration": [], + "metadata": { + "filter_scopes": {"1": {"filter_name": {"immune": [2]}}}, + "native_filter_configuration": [], + }, + } + + +def test_update_native_filter_config_scope_excluded(app_context: None): + from superset.dashboards.commands.importers.v1.utils import update_id_refs + + config = { + "position": { + "CHART1": { + "id": "CHART1", + "meta": {"chartId": 101, "uuid": "uuid1"}, + "type": "CHART", + }, + "CHART2": { + "id": "CHART2", + "meta": {"chartId": 102, "uuid": "uuid2"}, + "type": "CHART", + }, + }, + "metadata": { + "native_filter_configuration": [{"scope": {"excluded": [101, 102]}}], + }, + } + chart_ids = {"uuid1": 1, "uuid2": 2} + dataset_info: Dict[str, Dict[str, Any]] = {} # not used + + fixed = update_id_refs(config, chart_ids, dataset_info) + assert fixed == { + "position": { + "CHART1": { + "id": "CHART1", + "meta": {"chartId": 1, "uuid": "uuid1"}, + "type": "CHART", + }, + "CHART2": { + "id": "CHART2", + "meta": {"chartId": 2, "uuid": "uuid2"}, + "type": "CHART", + }, + }, + "metadata": {"native_filter_configuration": [{"scope": {"excluded": [1, 2]}}]}, }