diff --git a/luigi/worker.py b/luigi/worker.py index d30de1b285..7f314537b1 100644 --- a/luigi/worker.py +++ b/luigi/worker.py @@ -572,9 +572,9 @@ def _announce_scheduling_failure(self, task, expl): owners=task._owner_list(), ) except Exception: - raise formatted_traceback = traceback.format_exc() self._email_unexpected_error(task, formatted_traceback) + raise def _email_complete_error(self, task, formatted_traceback): self._announce_scheduling_failure(task, formatted_traceback) diff --git a/test/worker_test.py b/test/worker_test.py index a114506c4e..e7cb58c894 100644 --- a/test/worker_test.py +++ b/test/worker_test.py @@ -1232,6 +1232,26 @@ def complete(self): "1 scheduling failure" in email and 'a_owner@test.com' in email for email in emails)) + @email_patch + def test_announce_scheduling_failure_unexpected_error(self, emails): + + class A(DummyTask): + owner_email = 'a_owner@test.com' + + def complete(self): + pass + + scheduler = Scheduler(batch_emails=True) + worker = Worker(scheduler) + a = A() + + with mock.patch.object(worker._scheduler, 'announce_scheduling_failure', side_effect=Exception('Unexpected')),\ + self.assertRaises(Exception): + worker.add(a) + self.assertTrue(len(emails) == 2) # One for `complete` error, one for exception in announcing. + self.assertTrue('Luigi: Framework error while scheduling' in emails[1]) + self.assertTrue('a_owner@test.com' in emails[1]) + @email_patch def test_requires_error(self, emails): class A(DummyTask):