fix: keep charge invoice updates charge-owned#4354
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughParses and materializes richer per-line invoice patches that include the originating PatchOperation, enforces that charge-backed (ChargeID) lines are present before mutating/deleting across mutable and immutable flows, and replaces snapshot-based usage-quantity checks with direct comparisons via new helpers. ChangesInvoice patch validation and application
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/charges/invoiceupdater/invoiceupdate.go (1)
653-675: 💤 Low valueTiny opportunity: fold the two
ensure*HasChargeIDhelpers into one.These two helpers are byte-for-byte identical aside from the parameter type. Totally fine to keep as-is for clarity, but if you'd like to tidy up, a small generic with a
ChargeID()accessor or a tiny interface would shed the duplication. Happy to leave this as a nit — not blocking.♻️ Sketch of a generic version (illustrative)
type chargeIDOwner interface { GetChargeID() *string GetLineID() string // or similar } func ensureLineHasChargeID(line chargeIDOwner, operation PatchOperation) error { if line == nil { return fmt.Errorf("line is nil for patch operation[%s]", operation) } chargeID := line.GetChargeID() if chargeID == nil || *chargeID == "" { return fmt.Errorf("line[%s] has no charge ID, charges invoice updater cannot apply patch operation[%s] to non-charge lines", line.GetLineID(), operation) } return nil }Only worth doing if
StandardLineandGatheringLinealready expose (or trivially can expose) those accessors — otherwise the current pair is perfectly readable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/invoiceupdater/invoiceupdate.go` around lines 653 - 675, The two functions ensureStandardLineHasChargeID and ensureGatheringLineHasChargeID are identical; replace them with a single helper by introducing a small interface (e.g., chargeIDOwner with methods GetChargeID() *string and GetLineID() string or equivalent accessors on billing.StandardLine and billing.GatheringLine) and implement a single ensureLineHasChargeID(line chargeIDOwner, operation PatchOperation) error that contains the nil-check and ChargeID validation; then update all call sites to use ensureLineHasChargeID and remove the duplicate functions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@openmeter/billing/charges/invoiceupdater/invoiceupdate.go`:
- Around line 653-675: The two functions ensureStandardLineHasChargeID and
ensureGatheringLineHasChargeID are identical; replace them with a single helper
by introducing a small interface (e.g., chargeIDOwner with methods GetChargeID()
*string and GetLineID() string or equivalent accessors on billing.StandardLine
and billing.GatheringLine) and implement a single ensureLineHasChargeID(line
chargeIDOwner, operation PatchOperation) error that contains the nil-check and
ChargeID validation; then update all call sites to use ensureLineHasChargeID and
remove the duplicate functions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 852d93b7-2c6f-4f16-8b38-8edce0ac21b3
📒 Files selected for processing (1)
openmeter/billing/charges/invoiceupdater/invoiceupdate.go
37c614e to
255cfa9
Compare
255cfa9 to
78c145b
Compare
Charge-backed invoice updates need to stay inside the charge-owned line lifecycle. Billing's generic quantity snapshotter recalculates usage outside charge realization state, which can overwrite charge-owned quantities and detailed-line projections and produce misleading immutable-invoice validation. This change keeps patch application constrained to charge-backed lines and compares the charge-provided target state directly, so billing reports invalid immutable changes without recalculating them.
Summary by CodeRabbit