Skip to content

Commit

Permalink
Merge pull request getredash#1793 from danielerapati/fix/alert_with_n…
Browse files Browse the repository at this point in the history
…o_query_result

safeguard alerts against empty query results
  • Loading branch information
arikfr authored Jun 28, 2017
2 parents 70292c8 + 23cb92c commit bf17bdc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,18 +1150,20 @@ def to_dict(self, full=True):

def evaluate(self):
data = json.loads(self.query_rel.latest_query_data.data)
# todo: safe guard for empty
value = data['rows'][0][self.options['column']]
op = self.options['op']

if op == 'greater than' and value > self.options['value']:
new_state = self.TRIGGERED_STATE
elif op == 'less than' and value < self.options['value']:
new_state = self.TRIGGERED_STATE
elif op == 'equals' and value == self.options['value']:
new_state = self.TRIGGERED_STATE
if data['rows']:
value = data['rows'][0][self.options['column']]
op = self.options['op']

if op == 'greater than' and value > self.options['value']:
new_state = self.TRIGGERED_STATE
elif op == 'less than' and value < self.options['value']:
new_state = self.TRIGGERED_STATE
elif op == 'equals' and value == self.options['value']:
new_state = self.TRIGGERED_STATE
else:
new_state = self.OK_STATE
else:
new_state = self.OK_STATE
new_state = self.UNKNOWN_STATE

return new_state

Expand Down

0 comments on commit bf17bdc

Please sign in to comment.