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.
This commit is contained in:
Rebecca Law
2021-04-27 08:36:34 +01:00
parent 68d28aa83b
commit 4f196316aa

View File

@@ -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) 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] 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( 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)) current_app.logger.info('Finished deleting {} notifications'.format(notification_type))