Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user UUIDs on export for Native Filter Configuration #18562

Merged
merged 10 commits into from
Feb 8, 2022
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 native_filter["scope"]["excluded"]
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
]

return fixed


Expand Down
51 changes: 47 additions & 4 deletions tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
# pylint: disable=import-outside-toplevel, unused-argument

from typing import Any, Dict
from typing import Any, cast, Dict
hughhhh marked this conversation as resolved.
Show resolved Hide resolved


def test_update_id_refs_immune_missing( # pylint: disable=invalid-name
Expand Down 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]}}]},
}