Repository navigation
fix(subscription): allow rate card currency changes in edits - #5213
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openmeterio/openmeter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughSubscription updates can now use a different currency for a replacement item version. The invoice currency remains unchanged. Integration tests cover currency defaults, explicit currency validation, and persisted item history. ChangesReplacement item currency edits
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Currency edits preserve historical item versions, and no remaining issue prevents merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Normal currency and invoice checks remain in place, but the broader validation removal may also allow changes to historical item currencies. The billing-history implications and behavior under overlapping edits need confirmation. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
| )) | ||
| } | ||
|
|
||
| if err := validateMaterializedItemCurrenciesUnchanged(currentView.Spec, newSpec); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Fetch the customer & validate the customer |
There was a problem hiding this comment.
Existing item currencies can change
SubscriptionService.Update accepts a complete spec, not only remove/add edits. A caller can change the currency of an item version at its existing phase, key, and index. With this check removed, the service accepts that change, then archives and recreates the indexed item with the new currency. That lets an update rewrite historical pricing terms instead of adding a new term at an effective time. Please allow currency changes for new replacement versions while protecting existing versions.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/subscription/service/servicevalidation.go
Line: 69-72
Comment:
**Existing item currencies can change**
`SubscriptionService.Update` accepts a complete spec, not only remove/add edits. A caller can change the currency of an item version at its existing phase, key, and index. With this check removed, the service accepts that change, then archives and recreates the indexed item with the new currency. That lets an update rewrite historical pricing terms instead of adding a new term at an effective time. Please allow currency changes for new replacement versions while protecting existing versions.
**Knowledge Base Used:**
- [Subscription lifecycle](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/subscription-lifecycle.md)
- [Product catalog and subscriptions](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/product-catalog-and-subscriptions.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| _, err = deps.WorkflowService.EditRunning(t.Context(), created.Subscription.NamespacedID, []subscription.Patch{ | ||
| patch.PatchRemoveItem{PhaseKey: phaseKey, ItemKey: itemKey}, | ||
| patch.PatchAddItem{ | ||
| PhaseKey: phaseKey, | ||
| ItemKey: itemKey, | ||
| CreateInput: subscription.SubscriptionItemSpec{ | ||
| CreateSubscriptionItemInput: subscription.CreateSubscriptionItemInput{ | ||
| CreateSubscriptionItemPlanInput: subscription.CreateSubscriptionItemPlanInput{ | ||
| PhaseKey: phaseKey, | ||
| ItemKey: itemKey, | ||
| RateCard: replacement, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, immediate) |
There was a problem hiding this comment.
Direct update path lacks coverage
These cases all replace an item through EditRunning with remove/add patches. They do not cover a direct SubscriptionService.Update that changes the currency at an existing item-version index, even though that service path lost its currency check and its service-layer tests. Add a test that distinguishes an existing-version change from a valid appended replacement; without it, a regression in historical pricing terms could go unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/subscription/workflow/service/edit_currency_test.go
Line: 102-117
Comment:
**Direct update path lacks coverage**
These cases all replace an item through `EditRunning` with remove/add patches. They do not cover a direct `SubscriptionService.Update` that changes the currency at an existing item-version index, even though that service path lost its currency check and its service-layer tests. Add a test that distinguishes an existing-version change from a valid appended replacement; without it, a regression in historical pricing terms could go unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Overview
Remove/add subscription edits incorrectly rejected a replacement rate card when its currency differed from an earlier version under the same item key. Remove the extra currency immutability check so an omitted currency defaults to the subscription invoice currency and an explicit currency follows normal resolution and validation.
Notes for reviewer
Summary by CodeRabbit
The PR should not merge until updates are prevented from changing the currency of an existing item version.
Fix with agent prompt
Summary
This PR removes subscription-update item-currency immutability, documents currency changes for replacement versions and migrations, and adds running-edit regression tests. The removed check also leaves direct updates able to change an existing version’s currency.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR Edit[Remove/add running edit] --> Spec[Complete target spec] Direct[Direct service update] --> Spec Spec --> Validate[Currency and spec validation] Validate --> Sync[Compare items by version index] Sync --> Replace[Archive and recreate changed item]Reviews (1) · Last reviewed commit: "fix(subscription): allow rate card curre..."