From c9265aab68f26b28a0ca9df479994fbdff1ca56d Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 1 May 2019 15:07:59 +0100 Subject: [PATCH] Don't do anything if the query doesn't yield results. --- app/dao/notifications_dao.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 9d28ceeb8..f21d6fff7 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -395,21 +395,22 @@ def insert_update_notification_history(notification_type, date_to_delete_from, s Notification.key_type != KEY_TYPE_TEST ).all() - stmt = insert(NotificationHistory).values( - notifications - ) + if notifications: + stmt = insert(NotificationHistory).values( + notifications + ) - stmt = stmt.on_conflict_do_update( - constraint="notification_history_pkey", - set_={"notification_status": stmt.excluded.status, - "billable_units": stmt.excluded.billable_units, - "updated_at": stmt.excluded.updated_at, - "sent_at": stmt.excluded.sent_at, - "sent_by": stmt.excluded.sent_by - } - ) - db.session.connection().execute(stmt) - db.session.commit() + stmt = stmt.on_conflict_do_update( + constraint="notification_history_pkey", + set_={"notification_status": stmt.excluded.status, + "billable_units": stmt.excluded.billable_units, + "updated_at": stmt.excluded.updated_at, + "sent_at": stmt.excluded.sent_at, + "sent_by": stmt.excluded.sent_by + } + ) + db.session.connection().execute(stmt) + db.session.commit() def _delete_letters_from_s3(