Skip to content

Commit

Permalink
Move session closing
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 8, 2019
1 parent 1f38a3c commit eff2931
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit eff2931

Please sign in to comment.