We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8e81744 commit eb410b4Copy full SHA for eb410b4
application/db/session.py
@@ -3,6 +3,7 @@
3
from typing import Iterator
4
import logging
5
from application.settings import get_settings
6
+from contextlib import contextmanager
7
8
# Set up logging
9
logger = logging.getLogger(__name__)
@@ -37,6 +38,10 @@ def get_session() -> Iterator[Session]:
37
38
db.close()
39
40
41
+@contextmanager
42
def get_context_session() -> Iterator[Session]:
- with SessionLocal() as session:
43
+ session = SessionLocal()
44
+ try:
45
yield session
46
+ finally:
47
+ session.close()
0 commit comments