From eff2931abaf257df38d35921099f770241c5ad07 Mon Sep 17 00:00:00 2001 From: Keiran Price Date: Thu, 8 Aug 2019 08:03:26 +0100 Subject: [PATCH] Move session closing --- common/database_helpers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/database_helpers.py b/common/database_helpers.py index b0c5153d..fdd30839 100644 --- a/common/database_helpers.py +++ b/common/database_helpers.py @@ -222,11 +222,14 @@ def get_row_by_id(table, id): :param id: the id of the record to find :return: the record retrieved """ - log.info(f" Querying {table.__tablename__} for record with ID: {id}") read_query = ReadQuery(table) - where_filter = WhereFilter("ID", id) - where_filter.apply_filter(read_query) - return read_query.get_single_result() + try: + log.info(f" Querying {table.__tablename__} for record with ID: {id}") + where_filter = WhereFilter("ID", id) + where_filter.apply_filter(read_query) + return read_query.get_single_result() + finally: + read_query.session.close() def delete_row_by_id(table, id): @@ -295,6 +298,7 @@ def get_filtered_row_count(table, filters): :param filters: the filters to be applied to the query :return: int: the count of the rows """ + try: log.info(f" getting count for {table.__tablename__}") count_query = CountQuery(table) for filter in filters: