From 9fced2b9d4be73dcf9f14b31c2eeaf87793a283d Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 11 Jul 2023 22:23:35 +0200 Subject: [PATCH] Use SQLAlchemy AsyncAttrs/awaitable_attrs when accessing oauth_accounts with lazy loading --- plugins/auth/fps_auth/backends.py | 2 +- plugins/auth/fps_auth/db.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/auth/fps_auth/backends.py b/plugins/auth/fps_auth/backends.py index e670cb8c..0a3882ca 100644 --- a/plugins/auth/fps_auth/backends.py +++ b/plugins/auth/fps_auth/backends.py @@ -114,7 +114,7 @@ def get_jwt_strategy() -> JWTStrategy: class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]): async def on_after_register(self, user: User, request: Optional[Request] = None): - for oauth_account in user.oauth_accounts: + for oauth_account in await user.awaitable_attrs.oauth_accounts: if oauth_account.oauth_name == "github": async with httpx.AsyncClient() as client: r = ( diff --git a/plugins/auth/fps_auth/db.py b/plugins/auth/fps_auth/db.py index a8c704b9..100f682f 100644 --- a/plugins/auth/fps_auth/db.py +++ b/plugins/auth/fps_auth/db.py @@ -11,7 +11,7 @@ SQLAlchemyUserDatabase, ) from sqlalchemy import JSON, Boolean, Column, String, Text -from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine +from sqlalchemy.ext.asyncio import AsyncAttrs, AsyncSession, async_sessionmaker, create_async_engine from sqlalchemy.orm import DeclarativeBase, Mapped, relationship from .config import _AuthConfig @@ -20,7 +20,7 @@ logger = logging.getLogger("auth") -class Base(DeclarativeBase): +class Base(AsyncAttrs, DeclarativeBase): pass