Skip to content

Commit eb410b4

Browse files
committed
Adding get_context_session
1 parent 8e81744 commit eb410b4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

application/db/session.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Iterator
44
import logging
55
from application.settings import get_settings
6+
from contextlib import contextmanager
67

78
# Set up logging
89
logger = logging.getLogger(__name__)
@@ -37,6 +38,10 @@ def get_session() -> Iterator[Session]:
3738
db.close()
3839

3940

41+
@contextmanager
4042
def get_context_session() -> Iterator[Session]:
41-
with SessionLocal() as session:
43+
session = SessionLocal()
44+
try:
4245
yield session
46+
finally:
47+
session.close()

0 commit comments

Comments
 (0)