You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2021/12/14 00:22:11 UTC
[superset] branch master updated: fix: import dash with missing immune ID (#17732)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new fceabf6 fix: import dash with missing immune ID (#17732)
fceabf6 is described below
commit fceabf6bc5f9eacb082f321185aa2c1cbe657a40
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Mon Dec 13 16:20:55 2021 -0800
fix: import dash with missing immune ID (#17732)
---
superset/dashboards/commands/importers/v1/utils.py | 4 +-
tests/unit_tests/dashboards/__init__.py | 16 +++++
tests/unit_tests/dashboards/commands/__init__.py | 16 +++++
.../dashboards/commands/importers/__init__.py | 16 +++++
.../dashboards/commands/importers/v1/__init__.py | 16 +++++
.../dashboards/commands/importers/v1/utils_test.py | 71 ++++++++++++++++++++++
6 files changed, 138 insertions(+), 1 deletion(-)
diff --git a/superset/dashboards/commands/importers/v1/utils.py b/superset/dashboards/commands/importers/v1/utils.py
index fd5b4ee..0067c2c 100644
--- a/superset/dashboards/commands/importers/v1/utils.py
+++ b/superset/dashboards/commands/importers/v1/utils.py
@@ -90,7 +90,9 @@ def update_id_refs( # pylint: disable=too-many-locals
for columns in metadata["filter_scopes"].values():
for attributes in columns.values():
attributes["immune"] = [
- id_map[old_id] for old_id in attributes["immune"]
+ id_map[old_id]
+ for old_id in attributes["immune"]
+ if old_id in id_map
]
if "expanded_slices" in metadata:
diff --git a/tests/unit_tests/dashboards/__init__.py b/tests/unit_tests/dashboards/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tests/unit_tests/dashboards/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/unit_tests/dashboards/commands/__init__.py b/tests/unit_tests/dashboards/commands/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tests/unit_tests/dashboards/commands/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/unit_tests/dashboards/commands/importers/__init__.py b/tests/unit_tests/dashboards/commands/importers/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tests/unit_tests/dashboards/commands/importers/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/unit_tests/dashboards/commands/importers/v1/__init__.py b/tests/unit_tests/dashboards/commands/importers/v1/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tests/unit_tests/dashboards/commands/importers/v1/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
new file mode 100644
index 0000000..7ff8294
--- /dev/null
+++ b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
@@ -0,0 +1,71 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=import-outside-toplevel, unused-argument
+
+from typing import Any, Dict
+
+
+def test_update_id_refs_immune_missing( # pylint: disable=invalid-name
+ app_context: None,
+):
+ """
+ Test that missing immune charts are ignored.
+
+ A chart might be removed from a dashboard but still remain in the list of charts
+ immune to filters. The missing chart ID should be simply ignored when the
+ dashboard is imported.
+ """
+ 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": {
+ "filter_scopes": {"101": {"filter_name": {"immune": [102, 103],},},},
+ },
+ "native_filter_configuration": [],
+ }
+ 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": {"filter_scopes": {"1": {"filter_name": {"immune": [2]}}}},
+ "native_filter_configuration": [],
+ }