Skip to content

Commit

Permalink
fix(assets import): Ensure old datasource ids are not referenced in i…
Browse files Browse the repository at this point in the history
…mported charts (apache#25086)
  • Loading branch information
jfrag1 authored Aug 28, 2023
1 parent b5bac6c commit b240b79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion superset/commands/importers/v1/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down

0 comments on commit b240b79

Please sign in to comment.