From c2fe1b04bb40cf268a50cc1a982044cdfa24be98 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Thu, 21 Oct 2021 15:02:39 +0100 Subject: [PATCH] Fix test checking for nested exception Previously this type of exception was raised at the top level and the task did not retry [1]. Since Celery 4+ the behaviour changed so that a Retry exception will be raised unless we explicitly say we want to raise the original one [2]. It's unclear if we actually want to retry this task for any type of exception, but it's out-of-scope for this PR to decide on this, so here we just reraise the exception to make it compatible with the new version of Celery and the existing test. [1]: https://github.com/alphagov/notifications-api/pull/2832/files#diff-926badba91648d56a973e16bd92da3345b23bc60dc89360119b1df08de52723fL77 [2]: https://github.com/celery/celery/commit/32b52ca875509b84d786e33ce2d39f62ab7ea050#diff-db604dd7cb51e386710260ff2eba378aac19ba11eec97904bbf097b68caeada6L625 --- app/celery/letters_pdf_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/celery/letters_pdf_tasks.py b/app/celery/letters_pdf_tasks.py index 3d4b335aa..8616c9fe5 100644 --- a/app/celery/letters_pdf_tasks.py +++ b/app/celery/letters_pdf_tasks.py @@ -85,12 +85,12 @@ def get_pdf_for_templated_letter(self, notification_id): args=(encrypted_data,), queue=QueueNames.SANITISE_LETTERS ) - except Exception: + except Exception as e: try: current_app.logger.exception( f"RETRY: calling create-letter-pdf task for notification {notification_id} failed" ) - self.retry(queue=QueueNames.RETRY) + self.retry(exc=e, queue=QueueNames.RETRY) except self.MaxRetriesExceededError: message = f"RETRY FAILED: Max retries reached. " \ f"The task create-letter-pdf failed for notification id {notification_id}. " \