Merge pull request #1084 from getredash/fix_dup_alerts

Fix #1049: duplicate alerts when data source belongs to multiple groups
This commit is contained in:
Arik Fraimovich
2016-05-30 14:42:05 +03:00
2 changed files with 12 additions and 1 deletions

View File

@@ -755,7 +755,8 @@ class Alert(ModelTimestampsMixin, BaseModel):
.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):

View File

@@ -25,3 +25,13 @@ class TestAlertAll(BaseTestCase):
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)