From 7194a01040c679d813c147f17bb6d346b16930ab Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Tue, 8 Feb 2022 16:10:40 -0500 Subject: [PATCH] fix: user UUIDs on export for Native Filter Configuration (#18562) * saving work for import * update * move logic to update ref * remove export updates * remove unneeded code * cleanup * Update superset/dashboards/commands/importers/v1/utils.py Co-authored-by: Beto Dealmeida * Update tests/unit_tests/dashboards/commands/importers/v1/utils_test.py Co-authored-by: Beto Dealmeida Co-authored-by: Beto Dealmeida --- .../dashboards/commands/importers/v1/utils.py | 6 +++ .../commands/importers/v1/utils_test.py | 49 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) 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]}}]}, }