diff --git a/hub/persistence/repositories/user.py b/hub/persistence/repositories/user.py index 791a4c02..cd6037ac 100644 --- a/hub/persistence/repositories/user.py +++ b/hub/persistence/repositories/user.py @@ -86,17 +86,20 @@ class User(Repository): except SQLAlchemyError as err: logger.error(f'Error while fetching user: {err}') - def get_by_name_and_application(self, name: str, application_id: int) -> Model: + def get_by_name_and_application(self, name: str, application_id: int) -> Union[Model, None]: """ Fetch user based on the email address :param name: User name :param application_id: User application name - :return: [User] matching the search criteria + :return: User matching the search criteria or None """ try: - return self.session.execute( + user = self.session.execute( select(Model).where(Model.name == name, Model.application_id == application_id) - ).first()[0] + ).first() + if user is not None: + user = user[0] + return user except SQLAlchemyError as err: logger.error(f'Error while fetching user by name and application: {err}')