From c01877c12693fee3d476258b73ad4eeade794278 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Tue, 14 Jun 2022 15:51:49 -0300 Subject: [PATCH] fix: Unable to export multiple Dashboards with the same name --- superset/dashboards/commands/export.py | 2 +- .../integration_tests/dashboards/commands_tests.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/superset/dashboards/commands/export.py b/superset/dashboards/commands/export.py index c7aa8b6e5c65b..2d131d8f84e1c 100644 --- a/superset/dashboards/commands/export.py +++ b/superset/dashboards/commands/export.py @@ -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, diff --git a/tests/integration_tests/dashboards/commands_tests.py b/tests/integration_tests/dashboards/commands_tests.py index e3e6971155b9f..d382a5f50d1b2 100644 --- a/tests/integration_tests/dashboards/commands_tests.py +++ b/tests/integration_tests/dashboards/commands_tests.py @@ -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", } @@ -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(): @@ -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", @@ -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)) @@ -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())