Skip to content

Commit

Permalink
Merge pull request #1084 from getredash/fix_dup_alerts
Browse files Browse the repository at this point in the history
Fix #1049: duplicate alerts when data source belongs to multiple groups
  • Loading branch information
arikfr committed May 30, 2016
2 parents 6edb0ca + 07d2b5b commit e831218
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ def all(cls, groups):
.join(DataSourceGroup, on=(Query.data_source==DataSourceGroup.data_source))\
.where(DataSourceGroup.group << groups)\
.switch(Alert)\
.join(User)
.join(User)\
.group_by(Alert, User, Query)

@classmethod
def get_by_id_and_org(cls, id, org):
Expand Down
10 changes: 10 additions & 0 deletions tests/models/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def test_returns_all_alerts_for_given_groups(self):
alerts = Alert.all(groups=[group])
self.assertNotIn(alert1, alerts)
self.assertIn(alert2, alerts)

def test_return_each_alert_only_once(self):
group = self.factory.create_group()
self.factory.data_source.add_group(group)

alert = self.factory.create_alert()

alerts = Alert.all(groups=[self.factory.default_group, group])
self.assertEqual(1, len(list(alerts)))
self.assertIn(alert, alerts)

0 comments on commit e831218

Please sign in to comment.