From ecb09edcfbf20a9d37a641dca0eae6b78c92586a Mon Sep 17 00:00:00 2001 From: guille Date: Mon, 13 Mar 2023 15:01:55 -0400 Subject: [PATCH] Reintroduce function in business logic --- hub/persistence/repositories/user.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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}')