22from typing import TypedDict
33
44import sqlalchemy as sa
5- from aiopg .sa import Engine
6- from aiopg .sa .result import ResultProxy
75from models_library .basic_types import IdInt
86from models_library .products import ProductName
97from models_library .users import UserID
108from pydantic import TypeAdapter
119from simcore_postgres_database .models .groups import user_to_groups
1210from simcore_postgres_database .models .products import products
1311from simcore_postgres_database .models .users import UserRole
12+ from sqlalchemy .ext .asyncio import AsyncEngine
1413
1514from ..db .models import UserStatus , users
1615
@@ -22,33 +21,38 @@ class AuthInfoDict(TypedDict, total=True):
2221 role : UserRole
2322
2423
25- async def get_active_user_or_none (engine : Engine , email : str ) -> AuthInfoDict | None :
24+ async def get_active_user_or_none (
25+ engine : AsyncEngine , * , email : str
26+ ) -> AuthInfoDict | None :
2627 """Gets a user with email if ACTIVE othewise return None
2728
2829 Raises:
29- DatabaseError: unexpected errors found in https://github.com/ITISFoundation/osparc-simcore/issues/880 and https://github.com/ITISFoundation/osparc-simcore/pull/1160
30+ DatabaseError: unexpected errors found in
31+ https://github.com/ITISFoundation/osparc-simcore/issues/880 and
32+ https://github.com/ITISFoundation/osparc-simcore/pull/1160
3033 """
31- async with engine .acquire () as conn :
32- result : ResultProxy = await conn .execute (
34+ async with engine .connect () as conn :
35+ result = await conn .execute (
3336 sa .select (users .c .id , users .c .role ).where (
3437 (users .c .email == email ) & (users .c .status == UserStatus .ACTIVE )
3538 )
3639 )
37- row = await result .fetchone ()
38- assert (
39- row is None or TypeAdapter (IdInt ).validate_python (row .id ) is not None # nosec
40+ row = result .one_or_none ()
41+
42+ assert ( # nosec
43+ row is None or TypeAdapter (IdInt ).validate_python (row .id ) is not None
4044 )
41- assert (
42- row is None or TypeAdapter (UserRole ).validate_python (row .role ) is not None # nosec
45+ assert ( # nosec
46+ row is None or TypeAdapter (UserRole ).validate_python (row .role ) is not None
4347 )
4448
4549 return AuthInfoDict (id = row .id , role = row .role ) if row else None
4650
4751
4852async def is_user_in_product_name (
49- engine : Engine , user_id : UserID , product_name : ProductName
53+ engine : AsyncEngine , * , user_id : UserID , product_name : ProductName
5054) -> bool :
51- async with engine .acquire () as conn :
55+ async with engine .connect () as conn :
5256 return (
5357 await conn .scalar (
5458 sa .select (users .c .id )
0 commit comments