diff --git a/superset/models/alerts.py b/superset/models/alerts.py index b61baefab52ca..95e7c06042d90 100644 --- a/superset/models/alerts.py +++ b/superset/models/alerts.py @@ -203,7 +203,7 @@ def alert(self) -> RelationshipProperty: backref=backref("validators", cascade="all, delete-orphan"), ) - def __str__(self) -> str: + def pretty_print(self) -> str: """ String representing the comparison that will trigger a validator """ config = json.loads(self.config) diff --git a/superset/tasks/schedules.py b/superset/tasks/schedules.py index 94808a8e21dc0..d1fabc9f3e6d4 100644 --- a/superset/tasks/schedules.py +++ b/superset/tasks/schedules.py @@ -105,7 +105,7 @@ class AlertContent(NamedTuple): label: str # alert name sql: str # sql statement for alert observation_value: str # value from observation that triggered the alert - validation_str: str # a string of the comparison that triggered an alert + validation_error_message: str # a string of the comparison that triggered an alert alert_url: str # url to alert details image_data: Optional[ScreenshotData] # data for the alert screenshot @@ -575,8 +575,8 @@ def deliver_alert( # where an alert might not have a validator recipients = recipients or alert.recipients slack_channel = slack_channel or alert.slack_channel - validation_str = ( - str(alert.observations[-1].value) + " " + str(alert.validators[0]) + validation_error_message = ( + str(alert.observations[-1].value) + " " + alert.validators[0].pretty_print() if alert.validators else "" ) @@ -586,7 +586,7 @@ def deliver_alert( alert.label, alert.sql_observer[0].sql, str(alert.observations[-1].value), - validation_str, + validation_error_message, _get_url_path("AlertModelView.show", user_friendly=True, pk=alert_id), _get_slice_screenshot(alert.slice.id), ) @@ -596,7 +596,7 @@ def deliver_alert( alert.label, alert.sql_observer[0].sql, str(alert.observations[-1].value), - validation_str, + validation_error_message, _get_url_path("AlertModelView.show", user_friendly=True, pk=alert_id), None, ) @@ -626,7 +626,7 @@ def deliver_email_alert(alert_content: AlertContent, recipients: str) -> None: label=alert_content.label, sql=alert_content.sql, observation_value=alert_content.observation_value, - validation_str=alert_content.validation_str, + validation_error_message=alert_content.validation_error_message, image_url=image_url, ) @@ -645,7 +645,7 @@ def deliver_slack_alert(alert_content: AlertContent, slack_channel: str) -> None label=alert_content.label, sql=alert_content.sql, observation_value=alert_content.observation_value, - validation_str=alert_content.validation_str, + validation_error_message=alert_content.validation_error_message, url=alert_content.image_data.url, alert_url=alert_content.alert_url, ) @@ -656,7 +656,7 @@ def deliver_slack_alert(alert_content: AlertContent, slack_channel: str) -> None label=alert_content.label, sql=alert_content.sql, observation_value=alert_content.observation_value, - validation_str=alert_content.validation_str, + validation_error_message=alert_content.validation_error_message, alert_url=alert_content.alert_url, ) diff --git a/superset/templates/email/alert.txt b/superset/templates/email/alert.txt index 1e823ae977bac..964a57e3ccef2 100644 --- a/superset/templates/email/alert.txt +++ b/superset/templates/email/alert.txt @@ -20,7 +20,7 @@

Query:

{{sql}}

Result: {{observation_value}}

-

Reason: {{validation_str}}

+

Reason: {{validation_error_message}}

View Alert Details

Click here or the image below to view the chart related to this alert.

diff --git a/superset/templates/slack/alert.txt b/superset/templates/slack/alert.txt index 223c7f965b7c4..df943f5ef090e 100644 --- a/superset/templates/slack/alert.txt +++ b/superset/templates/slack/alert.txt @@ -19,6 +19,6 @@ *Triggered Alert: {{label}} :redalert:* *Query*:```{{sql}}``` *Result*: {{observation_value}} -*Reason*: {{validation_str}} +*Reason*: {{validation_error_message}} <{{alert_url}}|View Alert Details> <{{url}}|*Explore in Superset*> diff --git a/superset/templates/slack/alert_no_screenshot.txt b/superset/templates/slack/alert_no_screenshot.txt index fd48da94aa71d..bca191bb035a2 100644 --- a/superset/templates/slack/alert_no_screenshot.txt +++ b/superset/templates/slack/alert_no_screenshot.txt @@ -19,5 +19,5 @@ *Triggered Alert: {{label}} :redalert:* *Query*:```{{sql}}``` *Result*: {{observation_value}} -*Reason*: {{validation_str}} +*Reason*: {{validation_error_message}} <{{alert_url}}|View Alert Details> diff --git a/tests/alerts_tests.py b/tests/alerts_tests.py index 5659447b75a9e..a2226107a01d8 100644 --- a/tests/alerts_tests.py +++ b/tests/alerts_tests.py @@ -330,7 +330,7 @@ def test_deliver_alert_screenshot( "initial_comment": f"\n*Triggered Alert: {alert.label} :redalert:*\n" f"*Query*:```{alert.sql_observer[0].sql}```\n" f"*Result*: {alert.observations[-1].value}\n" - f"*Reason*: {alert.observations[-1].value} {str(alert.validators[0])}\n" + f"*Reason*: {alert.observations[-1].value} {alert.validators[0].pretty_print()}\n" f"\n",