From a499cea84aa79ce04d77a14ff0f90c383f726a3a Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Fri, 9 Dec 2022 15:06:05 -0800 Subject: [PATCH] fix string interpolation and add error message --- superset/tasks/scheduler.py | 7 ++-- .../reports/scheduler_tests.py | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/superset/tasks/scheduler.py b/superset/tasks/scheduler.py index 7472f68554121..b3efa240fa52d 100644 --- a/superset/tasks/scheduler.py +++ b/superset/tasks/scheduler.py @@ -69,7 +69,7 @@ def scheduler() -> None: active_schedule.id, schedule, ), - **async_options + **async_options, ) @@ -97,7 +97,10 @@ def execute(self: Celery.task, report_schedule_id: int, scheduled_dttm: str) -> except CommandException as ex: logger_func, level = get_logger_from_status(ex.status) logger_func( - "A downstream %s occurred while generating a report: %s", level, task_id + "A downstream {} occurred while generating a report: {}. {}".format( + level, task_id, ex.message + ), + exc_info=True, ) if level == LoggerLevel.EXCEPTION: self.update_state(state="FAILURE") diff --git a/tests/integration_tests/reports/scheduler_tests.py b/tests/integration_tests/reports/scheduler_tests.py index 76e4c4006e131..3dd6e72941e2e 100644 --- a/tests/integration_tests/reports/scheduler_tests.py +++ b/tests/integration_tests/reports/scheduler_tests.py @@ -179,3 +179,35 @@ def test_execute_task(update_state_mock, command_mock, init_mock, owners): db.session.delete(report_schedule) db.session.commit() + + +@pytest.mark.usefixtures("owners") +@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.__init__") +@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.run") +@patch("superset.tasks.scheduler.execute.update_state") +@patch("superset.utils.log.logger") +def test_execute_task_with_command_exception( + logger_mock, update_state_mock, command_mock, init_mock, owners +): + from superset.commands.exceptions import CommandException + + with app.app_context(): + report_schedule = insert_report_schedule( + type=ReportScheduleType.ALERT, + name=f"report-{randint(0,1000)}", + crontab="0 4 * * *", + timezone="America/New_York", + owners=owners, + ) + init_mock.return_value = None + command_mock.side_effect = CommandException("Unexpected error") + with freeze_time("2020-01-01T09:00:00Z"): + execute(report_schedule.id, "2020-01-01T09:00:00Z") + update_state_mock.assert_called_with(state="FAILURE") + logger_mock.exception.assert_called_with( + "A downstream exception occurred while generating a report: None. Unexpected error", + exc_info=True, + ) + + db.session.delete(report_schedule) + db.session.commit()