Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add link to Superset when report error #30576

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion superset/commands/report/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def _get_notification_content(self) -> NotificationContent:
name=self._report_schedule.name,
text=error_text,
header_data=header_data,
url=url,
)

if (
Expand Down Expand Up @@ -533,13 +534,14 @@ def send_error(self, name: str, message: str) -> None:
: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
Expand Down
12 changes: 9 additions & 3 deletions superset/reports/notifications/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ 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><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:
Expand Down Expand Up @@ -130,7 +133,6 @@ def _get_content(self) -> EmailContent:
else:
html_table = ""

call_to_action = __(app.config["EMAIL_REPORTS_CTA"])
img_tags = []
for msgid in images.keys():
img_tags.append(
Expand All @@ -140,6 +142,7 @@ def _get_content(self) -> EmailContent:
"""
)
img_tag = "".join(img_tags)
call_to_action = self._get_call_to_action()
body = textwrap.dedent(
f"""
<html>
Expand Down Expand Up @@ -190,6 +193,9 @@ def _get_subject(self) -> str:
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"]

Expand Down
5 changes: 5 additions & 0 deletions tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,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">Explore in Superset</a>' in email_mock.call_args[0][2]
)


@pytest.mark.usefixtures(