From 8aea452df969c6c22f46d9173054036022dc7f94 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 1 Mar 2018 16:38:42 +0000 Subject: [PATCH] Because research mode and test keys do not create notification history, a try except block has been added. --- app/celery/tasks.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 23b4fbd63..20b3088c2 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -19,6 +19,7 @@ from requests import ( RequestException ) from sqlalchemy.exc import SQLAlchemyError +from sqlalchemy.orm.exc import NoResultFound from app import ( create_uuid, @@ -42,6 +43,7 @@ from app.dao.notifications_dao import ( dao_get_last_notification_added_for_job_id, update_notification_status_by_reference, dao_get_notification_history_by_reference, + dao_get_notification_by_reference, ) from app.dao.provider_details_dao import get_current_provider from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service @@ -449,7 +451,12 @@ def update_letter_notification(filename, temporary_failures, update): def check_billable_units(notification_update): - notification = dao_get_notification_history_by_reference(notification_update.reference) + try: + # This try except is necessary because in test keys and research mode does not create notification history. + # Otherwise we could just search for the NotificationHistory object + notification = dao_get_notification_by_reference(notification_update.reference) + except NoResultFound: + notification = dao_get_notification_history_by_reference(notification_update.reference) if int(notification_update.page_count) != notification.billable_units: msg = 'Notification with id {} had {} billable_units but a page count of {}'.format(