Skip to content

Commit

Permalink
fix: Handle zero case for API usage limit (#4428)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Jul 30, 2024
1 parent d4006c0 commit 04e8bc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/organisations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions api/organisations/task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04e8bc2

Please sign in to comment.