Skip to content

Commit

Permalink
fix: user UUIDs on export for Native Filter Configuration (#18562)
Browse files Browse the repository at this point in the history
* 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 <roberto@dealmeida.net>

* Update tests/unit_tests/dashboards/commands/importers/v1/utils_test.py

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
  • Loading branch information
hughhhh and betodealmeida committed Feb 8, 2022
1 parent 11d71d6 commit 7194a01
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions superset/dashboards/commands/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
49 changes: 46 additions & 3 deletions tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]}}]},
}

0 comments on commit 7194a01

Please sign in to comment.