diff --git a/auth/authenticate.py b/auth/authenticate.py index d12924dc..a361b699 100644 --- a/auth/authenticate.py +++ b/auth/authenticate.py @@ -58,6 +58,7 @@ def login_required(func): async def wrap(parent, info: GraphQLResolveInfo, *args, **kwargs): # print('[auth.authenticate] login required for %r with info %r' % (func, info)) # debug only auth: AuthCredentials = info.context["request"].auth + print('[auth.authenticate] request auth data: %r' % auth) # debug only if not auth.logged_in: return {"error": auth.error_message or "Please login"} return await func(parent, info, *args, **kwargs) diff --git a/services/auth/users.py b/services/auth/users.py index df6a84ee..2ba636bc 100644 --- a/services/auth/users.py +++ b/services/auth/users.py @@ -1,5 +1,5 @@ import asyncio -from sqlalchemy.orm import selectinload +from sqlalchemy.orm import selectinload, exc from orm.user import User from base.orm import local_session @@ -22,16 +22,18 @@ class UserStorage: @staticmethod async def get_user(id): with local_session() as session: - user = ( - session.query(User).options( - selectinload(User.roles), - selectinload(User.ratings) - ).filter( - User.id == id - ).one() - ) - - return user + try: + user = ( + session.query(User).options( + selectinload(User.roles), + selectinload(User.ratings) + ).filter( + User.id == id + ).one() + ) + return user + except exc.NoResultFound: + return None @staticmethod async def get_all_users():