Skip to content

Commit

Permalink
Fix: pagination is broken on the dashboard list page (#5516)
Browse files Browse the repository at this point in the history
* Add test that reproduces issue #5466

* Fix: Duplicate dashboard rows were returned by Dashboard.all() (#5466)
  • Loading branch information
Jesse authored and susodapop committed Oct 2, 2021
1 parent 7cac149 commit 742db57
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def all(cls, org, group_ids, user_id):
joinedload(Dashboard.user).load_only(
"id", "name", "_profile_image_url", "email"
)
)
).distinct(Dashboard.created_at, Dashboard.slug)
.outerjoin(Widget)
.outerjoin(Visualization)
.outerjoin(Query)
Expand Down
29 changes: 29 additions & 0 deletions tests/models/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,32 @@ def test_returns_drafts_by_the_user(self):
# not using self.assertIn/NotIn because otherwise this fails :O
self.assertTrue(d in dashboards)
self.assertFalse(d2 in dashboards)


def test_returns_correct_number_of_dashboards(self):
# Solving https://github.com/getredash/redash/issues/5466

usr = self.factory.create_user()

ds1 = self.factory.create_data_source()
ds2 = self.factory.create_data_source()

qry1 = self.factory.create_query(data_source=ds1, user=usr)
qry2 = self.factory.create_query(data_source=ds2, user=usr)

viz1 = self.factory.create_visualization(query_rel=qry1, )
viz2 = self.factory.create_visualization(query_rel=qry2, )

def create_dashboard():
dash = self.factory.create_dashboard(name="boy howdy", user=usr)
self.factory.create_widget(dashboard=dash, visualization=viz1)
self.factory.create_widget(dashboard=dash, visualization=viz2)

return dash

d1 = create_dashboard()
d2 = create_dashboard()

results = Dashboard.all(self.factory.org, usr.group_ids, usr.id)

self.assertEqual(2, results.count(), "The incorrect number of dashboards were returned")

0 comments on commit 742db57

Please sign in to comment.