Skip to content

Commit

Permalink
Only create subscription object when it does not exist for user
Browse files Browse the repository at this point in the history
This avoid unnecessarily throwing an internal server error when the
user tries to sign-up using multiple mechanisms (e.g first by email, then
by google oauth)
  • Loading branch information
debanjum committed Dec 1, 2024
1 parent fc6be54 commit 8b8e2be
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/khoj/database/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ async def acreate_user_by_phone_number(phone_number: str) -> KhojUser:
)
await user.asave()

await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD)
user_subscription = await Subscription.objects.filter(user=user).afirst()
if not user_subscription:
await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD)

return user

Expand Down Expand Up @@ -296,7 +298,9 @@ async def create_user_by_google_token(token: dict) -> KhojUser:
user=user,
)

await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD)
user_subscription = await Subscription.objects.filter(user=user).afirst()
if not user_subscription:
await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD)

return user

Expand Down

0 comments on commit 8b8e2be

Please sign in to comment.