Skip to content

Commit 5b7de32

Browse files
committed
fix: removes references to session_context
session_context is meant to be able to provide us a context which commit the session and closes the connection, this is not understood and documented for the async world, until such point that we do understand this properly, this should not be used
1 parent 616261a commit 5b7de32

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

src/labs/db.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ async def init_models():
4343

4444
# TODO: Revise implementation in async context
4545
# Donot use until we have a better understanding of how to use async context
46-
@asynccontextmanager
47-
async def session_context():
48-
"""Provide a transactional scope around a series of operations.
49-
"""
50-
try:
51-
yield async_session
52-
await async_session.commit()
53-
except: # noqa: E722
54-
await async_session.rollback()
55-
raise
56-
finally:
57-
await async_session.close()
46+
# @asynccontextmanager
47+
# async def session_context():
48+
# """Provide a transactional scope around a series of operations.
49+
# """
50+
# try:
51+
# yield async_session
52+
# await async_session.commit()
53+
# except: # noqa: E722
54+
# await async_session.rollback()
55+
# raise
56+
# finally:
57+
# await async_session.close()

src/labs/routers/auth/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sqlalchemy.ext.asyncio import AsyncSession
1212

1313

14-
from ...db import session_context, get_async_session
14+
from ...db import get_async_session
1515
from ...models import User
1616
from ...schema import UserRequest,\
1717
PasswordLoginRequest, AuthResponse
@@ -56,7 +56,7 @@ async def login_user(request: PasswordLoginRequest,
5656
operation_id="refresh_token",
5757
)
5858
async def refresh_jwt_token(request: Request,
59-
session: AsyncSession = Depends(session_context)):
59+
session: AsyncSession = Depends(get_async_session)):
6060
""" Provides a refresh token for the JWT session.
6161
"""
6262
return {}
@@ -66,15 +66,15 @@ async def refresh_jwt_token(request: Request,
6666
summary=""" Provides an endpoint for logging out the user""",
6767
operation_id="logout_user"
6868
)
69-
async def logout_user(session: AsyncSession = Depends(session_context)):
69+
async def logout_user(session: AsyncSession = Depends(get_async_session)):
7070
""" Ends a users session
7171
7272
"""
7373
return {}
7474

7575
@router.get("/me", response_model=UserRequest)
7676
async def get_me(request: Request,
77-
session: AsyncSession = Depends(session_context)
77+
session: AsyncSession = Depends(get_async_session)
7878
):
7979
"""Get the currently logged in user or myself
8080

src/labs/routers/ext/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fastapi import APIRouter, Request, Depends
55
from sqlalchemy.ext.asyncio import AsyncSession
66

7-
from ...db import session_context, session_context
7+
from ...db import get_async_session
88
from ...config import config
99

1010
router = APIRouter(tags=["ext"])
@@ -25,13 +25,12 @@ async def get_health(request: Request):
2525
Purpose of this endpoint is to check the health of the server.
2626
We check for connection to the database, queue and logger
2727
"""
28-
async with session_context() as session:
29-
return {"message": "ok"}
28+
return {"message": "ok"}
3029

3130

3231
@router.get("/log")
3332
async def test_logger(request: Request,
34-
session: AsyncSession = Depends(session_context)
33+
session: AsyncSession = Depends(get_async_session)
3534
):
3635
"""Log a message.
3736

0 commit comments

Comments
 (0)