-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Add command for adding schedules to subscriptions #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
a1aafd4 to
7e2f900
Compare
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Outdated
Show resolved
Hide resolved
| # If the user is not in a schedule, update immediately | ||
| # If the user is in a schedule, update the existing schedule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment was actually already no longer correct and had not been updated. This handler has been releasing the existing schedule for a long time.
apps/codecov-api/billing/management/commands/apply_subscription_schedules.py
Show resolved
Hide resolved
938002c to
f36f356
Compare
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (78.46%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #707 +/- ##
==========================================
- Coverage 92.25% 92.20% -0.06%
==========================================
Files 1302 1303 +1
Lines 47854 48047 +193
Branches 1628 1628
==========================================
+ Hits 44149 44300 +151
- Misses 3396 3438 +42
Partials 309 309
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (78.46%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| phase1_quantity=desired_plan["quantity"], | ||
| subscription=subscription, | ||
| task_signature=WEBHOOK_CANCELLATION_TASK_SIGNATURE, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schedule recreation failure prevents DB plan update
Medium Severity
_create_end_date_schedule is called between the successful Subscription.modify and plan_service.update_plan. If the schedule recreation fails (Stripe API error, network issue), the exception propagates, skipping the DB update. This leaves the subscription upgraded in Stripe but the owner's plan stale in the database, and the previously released cancellation schedule is permanently lost.
Additional Locations (1)
| ) | ||
| from billing.management.commands.apply_subscription_schedules import ( | ||
| _create_end_date_schedule, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shared utility function lives inside management command
Low Severity
_create_end_date_schedule is defined as a private function (underscore prefix) inside a management command module but is imported by production service code in billing.py. This inverts the expected dependency direction — services typically feed management commands, not vice versa. The function belongs in a shared module like billing/utils.py or billing/services.py.


Adds general command for the team to run to bulk add subscription schedules for Owners. It will procure the matching owners based on the arguments and process each.
Takes these as user provided arguments:
Handles multiple scenarios for each owner
The command will return a summary of what happened and the owner id for the last acted upon owner.
PR also adds to the modify_subscription webhook handler logic to reapply the schedule if the subscription encounters an upgrade after the command has been run as upgrades will release schedules.
Note
Medium Risk
Touches Stripe subscription upgrade and scheduling logic; mistakes could incorrectly cancel, extend, or drop cancellation schedules for paying customers. Changes are test-covered but interact with live Stripe state and metadata conventions.
Overview
Adds a new
apply_subscription_schedulesDjango management command to bulk create/update StripeSubscriptionSchedules that cancel subscriptions at a specified end date, with filters (renewal date, plan, owner allow/deny lists), cursor-based batching, and a--dry-runmode.Introduces shared schedule
task_signatureconstants and reuses a new helper (_create_end_date_schedule) to make schedule creation idempotent and distinguish schedules created by the command/webhook. UpdatesStripeService.modify_subscriptionupgrade flow to detect and preserve prior cancellation end dates when releasing schedules (recreate after successful upgrade, and restore on upgrade failure). Adds comprehensive tests for the command and the new upgrade/schedule-recreation behavior.Written by Cursor Bugbot for commit f36f356. This will update automatically on new commits. Configure here.