chore: add link to Superset when report error (#30576)

This commit is contained in:
Elizabeth Thompson 2024-10-21 15:40:20 -07:00 committed by GitHub
parent f8fd2ec4ad
commit 4d5f70c694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 5 deletions

View File

@ -426,6 +426,7 @@ class BaseReportState:
name=self._report_schedule.name,
text=error_text,
header_data=header_data,
url=url,
)
if (
@ -533,13 +534,14 @@ class BaseReportState:
:raises: CommandException
"""
header_data = self._get_log_data()
url = self._get_url(user_friendly=True)
logger.info(
"header_data in notifications for alerts and reports %s, taskid, %s",
header_data,
self._execution_id,
)
notification_content = NotificationContent(
name=name, text=message, header_data=header_data
name=name, text=message, header_data=header_data, url=url
)
# filter recipients to recipients who are also owners

View File

@ -84,13 +84,17 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
def _get_smtp_domain() -> str:
return parseaddr(app.config["SMTP_MAIL_FROM"])[1].split("@")[1]
@staticmethod
def _error_template(text: str) -> str:
def _error_template(self, text: str) -> str:
call_to_action = self._get_call_to_action()
return __(
"""
Error: %(text)s
<p>Your report/alert was unable to be generated because of the following error: %(text)s</p>
<p>Please check your dashboard/chart for errors.</p>
<p><b><a href="%(url)s">%(call_to_action)s</a></b></p>
""",
text=text,
url=self._content.url,
call_to_action=call_to_action,
)
def _get_content(self) -> EmailContent:
@ -130,7 +134,6 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
else:
html_table = ""
call_to_action = __(app.config["EMAIL_REPORTS_CTA"])
img_tags = []
for msgid in images.keys():
img_tags.append(
@ -140,6 +143,7 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
"""
)
img_tag = "".join(img_tags)
call_to_action = self._get_call_to_action()
body = textwrap.dedent(
f"""
<html>
@ -190,6 +194,9 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
title=self._content.name,
)
def _get_call_to_action(self) -> str:
return __(app.config["EMAIL_REPORTS_CTA"])
def _get_to(self) -> str:
return json.loads(self._recipient.recipient_config_json)["target"]

View File

@ -1760,6 +1760,7 @@ def test_email_dashboard_report_fails_uncaught_exception(
screenshot_mock.return_value = SCREENSHOT_FILE
email_mock.side_effect = Exception("Uncaught exception")
app.config["EMAIL_REPORTS_CTA"] = "Call to action"
with pytest.raises(Exception):
AsyncExecuteReportScheduleCommand(
@ -1767,6 +1768,11 @@ def test_email_dashboard_report_fails_uncaught_exception(
).run()
assert_log(ReportState.ERROR, error_message="Uncaught exception")
assert (
'<a href="http://0.0.0.0:8080/superset/dashboard/'
f"{create_report_email_dashboard.dashboard.uuid}/"
'?force=false">Call to action</a>' in email_mock.call_args[0][2]
)
@pytest.mark.usefixtures(