From b94b2b7b84a1cd671ea462c55ba533783bbc03b7 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 8 Oct 2024 13:29:42 -0700 Subject: [PATCH] try by not closing session --- app/dao/services_dao.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index ff4d372de..2e05af00f 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -52,20 +52,15 @@ from app.utils import ( def dao_fetch_all_services(only_active=False): - stmt = ( - select(Service) - .order_by(asc(Service.created_at)) - .options(joinedload(Service.users)) - ) + stmt = select(Service) + if only_active: - stmt = ( - select(Service) - .where(Service.active is True) - .order_by(asc(Service.created_at)) - .options(joinedload(Service.users)) - ) - result = db.session.execute(stmt).unique() - return result.scalars().all() + stmt = stmt.where(Service.active) + + stmt = stmt.order_by(asc(Service.created_at)).options(joinedload(Service.users)) + + result = db.session.execute(stmt) + return result.unique().scalars().one() def get_services_by_partial_name(service_name):