Disambiguate renewal_date type. Previously, being used as None, False, and Datetime in different places.
Some checks are pending
dockerize / Publish Khoj Docker Images (push) Waiting to run
build and deploy github pages for documentation / deploy (push) Waiting to run
pre-commit / Setup Application and Lint (push) Waiting to run
pypi / Publish Python Package to PyPI (push) Waiting to run
test / Run Tests (push) Waiting to run

This commit is contained in:
sabaimran 2024-11-22 12:06:20 -08:00
parent 5e8c824ecc
commit 7f5bf35806
2 changed files with 3 additions and 3 deletions

View file

@ -345,7 +345,7 @@ async def set_user_subscription(
user_subscription.type = type
if is_recurring is not None:
user_subscription.is_recurring = is_recurring
if renewal_date is False:
if renewal_date is None:
user_subscription.renewal_date = None
elif renewal_date is not None:
user_subscription.renewal_date = renewal_date

View file

@ -67,7 +67,7 @@ async def subscribe(request: Request):
elif event_type in {"customer.subscription.updated"}:
user_subscription = await sync_to_async(adapters.get_user_subscription)(customer_email)
renewal_date = False
renewal_date = None
if subscription["current_period_end"]:
renewal_date = datetime.fromtimestamp(subscription["current_period_end"], tz=timezone.utc)
@ -82,7 +82,7 @@ async def subscribe(request: Request):
elif event_type in {"customer.subscription.deleted"}:
# Reset the user to trial state
user, is_new = await adapters.set_user_subscription(
customer_email, is_recurring=False, renewal_date=False, type=Subscription.Type.TRIAL
customer_email, is_recurring=False, renewal_date=None, type=Subscription.Type.TRIAL
)
success = user is not None