From 04e8bc2657d8b3657e9f12b54803911b74508123 Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Tue, 30 Jul 2024 13:51:54 -0400 Subject: [PATCH] fix: Handle zero case for API usage limit (#4428) --- api/organisations/models.py | 2 +- api/organisations/task_helpers.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/organisations/models.py b/api/organisations/models.py index 9a421ca5467d..3b818c85a463 100644 --- a/api/organisations/models.py +++ b/api/organisations/models.py @@ -452,7 +452,7 @@ class OrganisationSubscriptionInformationCache(LifecycleModelMixin, models.Model api_calls_30d = models.IntegerField(default=0) allowed_seats = models.IntegerField(default=1) - allowed_30d_api_calls = models.IntegerField(default=50000) + allowed_30d_api_calls = models.IntegerField(default=MAX_API_CALLS_IN_FREE_PLAN) allowed_projects = models.IntegerField(default=1, blank=True, null=True) chargebee_email = models.EmailField(blank=True, max_length=254, null=True) diff --git a/api/organisations/task_helpers.py b/api/organisations/task_helpers.py index 09d04602e2e5..96e99c671790 100644 --- a/api/organisations/task_helpers.py +++ b/api/organisations/task_helpers.py @@ -13,6 +13,7 @@ OrganisationAPIUsageNotification, OrganisationRole, ) +from organisations.subscriptions.constants import MAX_API_CALLS_IN_FREE_PLAN from users.models import FFAdminUser from .constants import API_USAGE_ALERT_THRESHOLDS @@ -114,6 +115,9 @@ def handle_api_usage_notification_for_organisation(organisation: Organisation) - api_usage = get_current_api_usage(organisation.id, f"-{days}d") + # For some reason the allowed API calls is set to 0 so default to the max free plan. + allowed_api_calls = allowed_api_calls or MAX_API_CALLS_IN_FREE_PLAN + api_usage_percent = int(100 * api_usage / allowed_api_calls) matched_threshold = None