Skip to content

Commit

Permalink
fix: Unable to export multiple Dashboards with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomedina248 committed Jun 14, 2022
1 parent 86f146e commit c01877c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion superset/dashboards/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _export(
model: Dashboard, export_related: bool = True
) -> Iterator[Tuple[str, str]]:
dashboard_slug = secure_filename(model.dashboard_title)
file_name = f"dashboards/{dashboard_slug}.yaml"
file_name = f"dashboards/{dashboard_slug}_{model.id}.yaml"

payload = model.export_to_dict(
recursive=False,
Expand Down
14 changes: 9 additions & 5 deletions tests/integration_tests/dashboards/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_export_dashboard_command(self, mock_g1, mock_g2):

expected_paths = {
"metadata.yaml",
"dashboards/World_Banks_Data.yaml",
f"dashboards/World_Banks_Data_{example_dashboard.id}.yaml",
"datasets/examples/wb_health_population.yaml",
"databases/examples.yaml",
}
Expand All @@ -77,7 +77,9 @@ def test_export_dashboard_command(self, mock_g1, mock_g2):
expected_paths.add(f"charts/{chart_slug}_{chart.id}.yaml")
assert expected_paths == set(contents.keys())

metadata = yaml.safe_load(contents["dashboards/World_Banks_Data.yaml"])
metadata = yaml.safe_load(
contents[f"dashboards/World_Banks_Data_{example_dashboard.id}.yaml"]
)

# remove chart UUIDs from metadata so we can compare
for chart_info in metadata["position"].values():
Expand Down Expand Up @@ -269,7 +271,9 @@ def test_export_dashboard_command_key_order(self, mock_g1, mock_g2):
command = ExportDashboardsCommand([example_dashboard.id])
contents = dict(command.run())

metadata = yaml.safe_load(contents["dashboards/World_Banks_Data.yaml"])
metadata = yaml.safe_load(
contents[f"dashboards/World_Banks_Data_{example_dashboard.id}.yaml"]
)
assert list(metadata.keys()) == [
"dashboard_title",
"description",
Expand All @@ -284,7 +288,7 @@ def test_export_dashboard_command_key_order(self, mock_g1, mock_g2):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@patch("superset.dashboards.commands.export.suffix")
def test_append_charts(self, mock_suffix):
"""Test that oprhaned charts are added to the dashbaord position"""
"""Test that orphaned charts are added to the dashboard position"""
# return deterministic IDs
mock_suffix.side_effect = (str(i) for i in itertools.count(1))

Expand Down Expand Up @@ -435,7 +439,7 @@ def test_export_dashboard_command_no_related(self, mock_g1, mock_g2):

expected_paths = {
"metadata.yaml",
"dashboards/World_Banks_Data.yaml",
f"dashboards/World_Banks_Data_{example_dashboard.id}.yaml",
}
assert expected_paths == set(contents.keys())

Expand Down

0 comments on commit c01877c

Please sign in to comment.