Skip to content

fix(usage): count whole years when resolving the current billing period - #8429

Closed
talissoncosta wants to merge 2 commits into
mainfrom
fix/current-billing-period-long-terms-6099
Closed

fix(usage): count whole years when resolving the current billing period#8429
talissoncosta wants to merge 2 commits into
mainfrom
fix/current-billing-period-long-terms-6099

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Sep 1, 2026

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #6099.

The current billing period was derived from relativedelta(now, starts_at).months, which drops whole years. A term that began more than twelve months ago resolved a year early, so the usage page reported a window over a year long against one month's allowance.

The same arithmetic existed in three places and was right in only one. It now lives in get_current_billing_period_start_date and all three use it: the usage query, the API usage notifications view, and the notification task. The view had the same bug, so a stale notification could be treated as current.

How did you test this code?

Unit tests for a term started 13 months ago, across the service, the usage query and the view.

The current period was derived from the months component of the delta between
now and the billing term start, so whole years were dropped. A term that began
more than twelve months ago resolved to a period a year early, and the usage
page reported a window over a year long instead of the current month.

The same arithmetic existed in three places and was correct in only one of
them, so it now lives in one function used by all three: the usage data query,
the API usage notifications view and the notification task. The view had the
same bug, which meant a stale notification could be treated as current.

Closes #6099

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 1, 2026 3:44pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Sep 1, 2026 3:44pm UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 1, 2026 3:44pm UTC

Request Review

@github-actions github-actions Bot added api Issue related to the REST API fix labels Sep 1, 2026
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (894bfa4) to head (3245515).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8429   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files        1621     1623    +2     
  Lines       66118    66145   +27     
=======================================
+ Hits        65334    65361   +27     
  Misses        784      784           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API docs Documentation updates fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect usage date ranges with long billing terms

1 participant