mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
try by not closing session
This commit is contained in:
@@ -3,7 +3,7 @@ from datetime import timedelta
|
|||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from sqlalchemy import Float, cast, select
|
from sqlalchemy import Float, cast, select
|
||||||
from sqlalchemy.orm import Session, joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
from sqlalchemy.sql.expression import and_, asc, case, func
|
from sqlalchemy.sql.expression import and_, asc, case, func
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
@@ -51,21 +51,21 @@ from app.utils import (
|
|||||||
|
|
||||||
|
|
||||||
def dao_fetch_all_services(only_active=False):
|
def dao_fetch_all_services(only_active=False):
|
||||||
with Session(db.engine) as session:
|
|
||||||
|
stmt = (
|
||||||
|
select(Service)
|
||||||
|
.order_by(asc(Service.created_at))
|
||||||
|
.options(joinedload(Service.users))
|
||||||
|
)
|
||||||
|
if only_active:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Service)
|
select(Service)
|
||||||
|
.where(Service.active is True)
|
||||||
.order_by(asc(Service.created_at))
|
.order_by(asc(Service.created_at))
|
||||||
.options(joinedload(Service.users))
|
.options(joinedload(Service.users))
|
||||||
)
|
)
|
||||||
if only_active:
|
result = db.session.execute(stmt).unique()
|
||||||
stmt = (
|
return result.scalars().all()
|
||||||
select(Service)
|
|
||||||
.where(Service.active is True)
|
|
||||||
.order_by(asc(Service.created_at))
|
|
||||||
.options(joinedload(Service.users))
|
|
||||||
)
|
|
||||||
result = session.execute(stmt).unique()
|
|
||||||
return result.scalars().all()
|
|
||||||
|
|
||||||
|
|
||||||
def get_services_by_partial_name(service_name):
|
def get_services_by_partial_name(service_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user