From cd4e45ccf4930790a6b76cba76baceaa03302374 Mon Sep 17 00:00:00 2001 From: Philip Herzog Date: Mon, 20 Nov 2023 09:58:42 +0100 Subject: [PATCH] added PR to ensure old datasource Ids are not referenced in imported Charts --- superset/dashboards/commands/importers/v1/__init__.py | 9 ++++++++- tests/integration_tests/dashboards/commands_tests.py | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/superset/dashboards/commands/importers/v1/__init__.py b/superset/dashboards/commands/importers/v1/__init__.py index 1720e01ab8bcc..443efc8d3bd3a 100644 --- a/superset/dashboards/commands/importers/v1/__init__.py +++ b/superset/dashboards/commands/importers/v1/__init__.py @@ -112,7 +112,14 @@ def _import( and config["dataset_uuid"] in dataset_info ): # update datasource id, type, and name - config.update(dataset_info[config["dataset_uuid"]]) + dataset_dict = dataset_info[config["dataset_uuid"]] + config.update(dataset_dict) + # pylint: disable=line-too-long + dataset_uid = f"{dataset_dict['datasource_id']}__{dataset_dict['datasource_type']}" + config["params"].update({"datasource": dataset_uid}) + if "query_context" in config: + del config["query_context"] + chart = import_chart(session, config, overwrite=False) chart_ids[str(chart.uuid)] = chart.id diff --git a/tests/integration_tests/dashboards/commands_tests.py b/tests/integration_tests/dashboards/commands_tests.py index e3e6971155b9f..88221f78b7ba2 100644 --- a/tests/integration_tests/dashboards/commands_tests.py +++ b/tests/integration_tests/dashboards/commands_tests.py @@ -560,6 +560,9 @@ def test_import_v1_dashboard(self, mock_g): dataset = chart.table assert str(dataset.uuid) == dataset_config["uuid"] + assert chart.query_context is None + assert json.loads(chart.params)["datasource"] == dataset.uid + database = dataset.database assert str(database.uuid) == database_config["uuid"]