From b31d9b07e24f73a8fb72dd2bb7a6773ca279e49d Mon Sep 17 00:00:00 2001 From: Camilo Avila Date: Mon, 5 Feb 2024 21:53:57 -0500 Subject: [PATCH] Refactored get_by_oauth_account on manager.py to handle missing of OAuthAccount on BaseUserDatabase --- fastapi_users/manager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fastapi_users/manager.py b/fastapi_users/manager.py index 65da8113..e3055286 100644 --- a/fastapi_users/manager.py +++ b/fastapi_users/manager.py @@ -98,9 +98,14 @@ async def get_by_oauth_account(self, oauth: str, account_id: str) -> models.UP: :param oauth: Name of the OAuth client. :param account_id: Id. of the account on the external OAuth service. :raises UserNotExists: The user does not exist. + :raises NotImplementedError: The OAuthAccount wasn't added to fastapi_users.db base. :return: A user. """ - user = await self.user_db.get_by_oauth_account(oauth, account_id) + try: + user = await self.user_db.get_by_oauth_account(oauth, account_id) + except NotImplementedError: + print("User manager does not support OAuth accounts. maybe you forgot add OAuthAccount to fastapi_users.db base?") + raise NotImplementedError if user is None: raise exceptions.UserNotExists()