From f941768d8cf094678a1c3dfa0b8919196026c03e Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 27 Apr 2021 08:36:34 +0100 Subject: [PATCH] Change the query to get the services to purge to use query on the db.Model rather than db.session.query. `service_ids_to_purge` is a list of `row` object rather than a list of `UUID`. NOTE: db.session.query(Service).filter(Service.id.notin_(services_with_data_retention)).all() would have also worked. It seems that only selecting attributes from the db.Model has caused the change. --- app/dao/notifications_dao.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index f858ab6c4..3caf04627 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -328,11 +328,11 @@ def delete_notifications_older_than_retention_by_type(notification_type, qry_lim seven_days_ago = get_london_midnight_in_utc(convert_utc_to_bst(datetime.utcnow()).date()) - timedelta(days=7) services_with_data_retention = [x.service_id for x in flexible_data_retention] - service_ids_to_purge = db.session.query(Service.id).filter(Service.id.notin_(services_with_data_retention)).all() + service_ids_to_purge = Service.query.filter(Service.id.notin_(services_with_data_retention)).all() - for service_id in service_ids_to_purge: + for service in service_ids_to_purge: deleted += _move_notifications_to_notification_history( - notification_type, service_id, seven_days_ago, qry_limit) + notification_type, service.id, seven_days_ago, qry_limit) current_app.logger.info('Finished deleting {} notifications'.format(notification_type))