diff --git a/superset/commands/importers/v1/assets.py b/superset/commands/importers/v1/assets.py index 1ab2e486cf3dd..f0720d70b19ad 100644 --- a/superset/commands/importers/v1/assets.py +++ b/superset/commands/importers/v1/assets.py @@ -79,6 +79,7 @@ def __init__(self, contents: dict[str, str], *args: Any, **kwargs: Any): ) self._configs: dict[str, Any] = {} + # pylint: disable=too-many-locals @staticmethod def _import(session: Session, configs: dict[str, Any]) -> None: # import databases first @@ -110,7 +111,13 @@ def _import(session: Session, configs: dict[str, Any]) -> None: chart_ids: dict[str, int] = {} for file_name, config in configs.items(): if file_name.startswith("charts/"): - 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=True) chart_ids[str(chart.uuid)] = chart.id diff --git a/tests/integration_tests/commands_test.py b/tests/integration_tests/commands_test.py index 86ebdc0951032..6512a141bea44 100644 --- a/tests/integration_tests/commands_test.py +++ b/tests/integration_tests/commands_test.py @@ -141,6 +141,9 @@ def test_import_assets(self): 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"]