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 #1049: duplicate alerts when data source belongs to multiple groups #1084

Merged
merged 1 commit into from
May 30, 2016
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
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)