This is an automated email from the ASF dual-hosted git repository. elizabeth pushed a commit to branch elizabeth/add-footer-error-report in repository https://gitbox.apache.org/repos/asf/superset.git
commit cd9c4c761f7f0ca964839a30d867fbee4ff222ce Author: Elizabeth Thompson <[email protected]> AuthorDate: Thu Oct 10 14:34:44 2024 -0700 add link to Superset when report error --- requirements/base.txt | 2 +- superset/commands/report/execute.py | 4 +++- superset/reports/notifications/email.py | 12 +++++++++--- tests/integration_tests/reports/commands_tests.py | 5 +++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 22540e3d7a..904b1a18fc 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -350,7 +350,7 @@ sqlalchemy-utils==0.38.3 # via # apache-superset # flask-appbuilder -sqlglot==23.6.3 +sqlglot==25.24.0 # via apache-superset sqlparse==0.5.0 # via apache-superset diff --git a/superset/commands/report/execute.py b/superset/commands/report/execute.py index eadf193bf4..afc488df56 100644 --- a/superset/commands/report/execute.py +++ b/superset/commands/report/execute.py @@ -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 diff --git a/superset/reports/notifications/email.py b/superset/reports/notifications/email.py index f5943f5392..c1a7621163 100644 --- a/superset/reports/notifications/email.py +++ b/superset/reports/notifications/email.py @@ -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 + <b><a href="%(url)s">%(call_to_action)s</a></b> """, text=text, + url=self._content.url, + call_to_action=call_to_action, ) def _get_content(self) -> EmailContent: @@ -130,7 +133,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 +142,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 +193,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"] diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index 575c8a02b9..b5f37d571f 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -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(
