Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unable to export multiple Dashboards with the same name #20383

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eagle eyes! :)

"""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