mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
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:
@@ -755,7 +755,8 @@ class Alert(ModelTimestampsMixin, BaseModel):
|
|||||||
.join(DataSourceGroup, on=(Query.data_source==DataSourceGroup.data_source))\
|
.join(DataSourceGroup, on=(Query.data_source==DataSourceGroup.data_source))\
|
||||||
.where(DataSourceGroup.group << groups)\
|
.where(DataSourceGroup.group << groups)\
|
||||||
.switch(Alert)\
|
.switch(Alert)\
|
||||||
.join(User)
|
.join(User)\
|
||||||
|
.group_by(Alert, User, Query)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_id_and_org(cls, id, org):
|
def get_by_id_and_org(cls, id, org):
|
||||||
|
|||||||
@@ -25,3 +25,13 @@ class TestAlertAll(BaseTestCase):
|
|||||||
alerts = Alert.all(groups=[group])
|
alerts = Alert.all(groups=[group])
|
||||||
self.assertNotIn(alert1, alerts)
|
self.assertNotIn(alert1, alerts)
|
||||||
self.assertIn(alert2, 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user