Skip to content

Commit

Permalink
fix: Copy dashboard filters when copying dashboard (apache#24303)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrag1 authored and pull[bot] committed Nov 7, 2024
1 parent b5d378d commit 57f5334
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/dashboards/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def copy_dashboard(
else:
dash.slices = original_dash.slices

dash.params = original_dash.params
cls.set_dash_metadata(dash, metadata, old_to_new_slice_ids)
db.session.add(dash)
db.session.commit()
Expand Down
28 changes: 28 additions & 0 deletions tests/integration_tests/dashboards/dao_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ def test_copy_dashboard(self, mock_g):
db.session.delete(dash)
db.session.commit()

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@patch("superset.dashboards.dao.g")
def test_copy_dashboard_copies_native_filters(self, mock_g):
mock_g.user = security_manager.find_user("admin")
original_dash = (
db.session.query(Dashboard).filter_by(slug="world_health").first()
)
# Give the original dash a "native filter"
original_dash_params = original_dash.params_dict
original_dash_params["native_filter_configuration"] = [{"mock": "filter"}]
original_dash.json_metadata = json.dumps(original_dash_params)

metadata = json.loads(original_dash.json_metadata)
metadata["positions"] = original_dash.position
dash_data = {
"dashboard_title": "copied dash",
"json_metadata": json.dumps(metadata),
"css": "<css>",
"duplicate_slices": False,
}
dash = DashboardDAO.copy_dashboard(original_dash, dash_data)
self.assertEqual(
dash.params_dict["native_filter_configuration"], [{"mock": "filter"}]
)

db.session.delete(dash)
db.session.commit()

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@patch("superset.dashboards.dao.g")
def test_copy_dashboard_duplicate_slices(self, mock_g):
Expand Down

0 comments on commit 57f5334

Please sign in to comment.