fix service_delete function to clean up template_redacted objects properly

This commit is contained in:
Leo Hemsted
2017-06-28 17:19:53 +01:00
parent 3f663daafe
commit 3a0bc01a55

View File

@@ -202,13 +202,16 @@ def dao_remove_user_from_service(service, user):
def delete_service_and_all_associated_db_objects(service):
def _delete_commit(query):
query.delete()
query.delete(synchronize_session=False)
db.session.commit()
job_stats = JobStatistics.query.join(Job).filter(Job.service_id == service.id)
list(map(db.session.delete, job_stats))
db.session.commit()
subq = db.session.query(Template.id).filter_by(service=service).subquery()
_delete_commit(TemplateRedacted.query.filter(TemplateRedacted.template_id.in_(subq)))
_delete_commit(NotificationStatistics.query.filter_by(service=service))
_delete_commit(TemplateStatistics.query.filter_by(service=service))
_delete_commit(ProviderStatistics.query.filter_by(service=service))
@@ -219,7 +222,6 @@ def delete_service_and_all_associated_db_objects(service):
_delete_commit(Job.query.filter_by(service=service))
_delete_commit(NotificationHistory.query.filter_by(service=service))
_delete_commit(Notification.query.filter_by(service=service))
_delete_commit(TemplateRedacted.query.filter_by(service=service))
_delete_commit(Template.query.filter_by(service=service))
_delete_commit(TemplateHistory.query.filter_by(service_id=service.id))
_delete_commit(ServicePermission.query.filter_by(service_id=service.id))