mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
don't crash when there is no data (#7208)
* don't crash when there is no data * Add test
This commit is contained in:
@@ -968,9 +968,9 @@ class Alert(TimestampMixin, BelongsToOrgMixin, db.Model):
|
||||
return super(Alert, cls).get_by_id_and_org(object_id, org, Query)
|
||||
|
||||
def evaluate(self):
|
||||
data = self.query_rel.latest_query_data.data
|
||||
data = self.query_rel.latest_query_data.data if self.query_rel.latest_query_data else None
|
||||
|
||||
if data["rows"] and self.options["column"] in data["rows"][0]:
|
||||
if data and data["rows"] and self.options["column"] in data["rows"][0]:
|
||||
op = OPERATORS.get(self.options["op"], lambda v, t: False)
|
||||
|
||||
if "selector" not in self.options:
|
||||
|
||||
@@ -111,6 +111,13 @@ class TestAlertEvaluate(BaseTestCase):
|
||||
alert.options["selector"] = "max"
|
||||
self.assertEqual(alert.evaluate(), Alert.UNKNOWN_STATE)
|
||||
|
||||
def test_evaluate_alerts_without_query_rel(self):
|
||||
query = self.factory.create_query(latest_query_data_id=None)
|
||||
alert = self.factory.create_alert(
|
||||
query_rel=query, options={"selector": "first", "op": "equals", "column": "foo", "value": "1"}
|
||||
)
|
||||
self.assertEqual(alert.evaluate(), Alert.UNKNOWN_STATE)
|
||||
|
||||
|
||||
class TestNextState(TestCase):
|
||||
def test_numeric_value(self):
|
||||
|
||||
Reference in New Issue
Block a user