fix(alerts): Handle None on results (#13289)

This commit is contained in:
Daniel Vaz Gaspar 2021-02-23 09:50:55 +00:00 committed by GitHub
parent 9e2455aab7
commit 6e3121268e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -52,7 +52,7 @@ class AlertCommand(BaseCommand):
if self._is_validator_not_null:
self._report_schedule.last_value_row_json = str(self._result)
return self._result is not None
return self._result not in (0, None, np.nan)
self._report_schedule.last_value = self._result
try:
operator = json.loads(self._report_schedule.validator_config_json)["op"]
@ -90,7 +90,8 @@ class AlertCommand(BaseCommand):
def _validate_operator(self, rows: np.recarray) -> None:
self._validate_result(rows)
if rows[0][1] is None:
if rows[0][1] in (0, None, np.nan):
self._result = 0.0
return
try:
# Check if it's float or if we can convert it

View File

@ -319,7 +319,17 @@ def create_alert_email_chart(request):
@pytest.yield_fixture(
params=["alert1", "alert2", "alert3", "alert4", "alert5", "alert6", "alert7"]
params=[
"alert1",
"alert2",
"alert3",
"alert4",
"alert5",
"alert6",
"alert7",
"alert8",
"alert9",
]
)
def create_no_alert_email_chart(request):
param_config = {
@ -358,6 +368,16 @@ def create_no_alert_email_chart(request):
"validator_type": ReportScheduleValidatorType.OPERATOR,
"validator_config_json": '{"op": ">", "threshold": 0}',
},
"alert8": {
"sql": "SELECT Null as metric",
"validator_type": ReportScheduleValidatorType.NOT_NULL,
"validator_config_json": "{}",
},
"alert9": {
"sql": "SELECT Null as metric",
"validator_type": ReportScheduleValidatorType.OPERATOR,
"validator_config_json": '{"op": ">", "threshold": 0}',
},
}
with app.app_context():
chart = db.session.query(Slice).first()