Skip to content

Commit

Permalink
Use SQLAlchemy AsyncAttrs/awaitable_attrs when accessing oauth_accoun…
Browse files Browse the repository at this point in the history
…ts with lazy loading
  • Loading branch information
davidbrochart committed Jul 11, 2023
1 parent 8c3b189 commit 9fced2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/auth/fps_auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth/fps_auth/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@
logger = logging.getLogger("auth")


class Base(DeclarativeBase):
class Base(AsyncAttrs, DeclarativeBase):
pass


Expand Down

0 comments on commit 9fced2b

Please sign in to comment.