From b63856ecb48d8d7b4f7bbd289bbc2b8f7190c748 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Wed, 15 Nov 2023 12:50:39 -0800 Subject: [PATCH] Update logic for creating a new user to use aupdate_or_create --- src/database/adapters/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/database/adapters/__init__.py b/src/database/adapters/__init__.py index a61b3d64..552e9124 100644 --- a/src/database/adapters/__init__.py +++ b/src/database/adapters/__init__.py @@ -80,10 +80,10 @@ async def get_or_create_user(token: dict) -> KhojUser: async def create_user_by_token(token: dict) -> KhojUser: - user = await KhojUser.objects.filter(email=token.get("email")).aget_or_none() - if not user: - user = await KhojUser.objects.acreate(username=token.get("email"), email=token.get("email")) - await user.asave() + user = await KhojUser.objects.filter(email=token.get("email")).aupdate_or_create( + defaults={"username": token.get("email"), "email": token.get("email")} + ) + await user.asave() await GoogleUser.objects.acreate( sub=token.get("sub"),