fix(api): non-existent tax code#4590
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 ignored due to path filters (1)
📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughCharge creation now validates referenced tax codes before persistence, maps charge constraint failures to domain errors, updates the credit-grant API contract, and adds end-to-end and service tests for missing tax code handling. ChangesTax code validation and error mapping
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@test/credits/creditgrant_test.go`:
- Around line 634-635: The current assertion in the credit grant test only
checks for GenericValidationError, so it can miss regressions in the specific
tax-code validation path. Update the test around the error handling in the
credit grant case to unwrap the validation error and assert the underlying issue
is tax_code_not_found, and ideally verify the field path is tax_config.tax_code
as well. Keep the existing validation check, but make it tax-code-specific so
the test fails if the wrong validation code or path is returned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c46390bb-b5f2-45f3-b6b5-4b3c1265d11b
📒 Files selected for processing (2)
openmeter/billing/charges/creditpurchase/adapter/charge.gotest/credits/creditgrant_test.go
Greptile SummaryThis PR improves tax-code handling for credit grants and charge creation. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "fix(api): non-existent tax code" | Re-trigger Greptile |
f010115 to
76987b9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/billing/charges/service/create.go (1)
73-103: 🚀 Performance & Scalability | 🔵 Trivial | 🏗️ Heavy liftConsider batching the tax-code existence check.
This adds one
GetTaxCodecall per distinct tax code before create runs, so large batches now pay an extra N round trips on a hot DB path. A batched lookup would keep the validation and avoid scaling linearly with batch cardinality.As per path instructions, "Performance should be a priority in critical code paths. Anything related to event ingestion, message processing, database operations (regardless of database) should be vetted for potential performance bottlenecks."
🤖 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/service/create.go` around lines 73 - 103, The tax-code validation in validateTaxCodesExist currently performs one GetTaxCode lookup per distinct taxCodeID, creating linear round trips on the create path. Refactor this logic to batch the existence check for all collected tax codes at once using the existing service/repository layer, then map missing IDs back to the same tax_code_not_found validation error while preserving the current deduping and empty-ID handling.Source: Path instructions
🤖 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.
Inline comments:
In `@openmeter/billing/charges/creditpurchase/adapter/charge.go`:
- Around line 93-98: Narrow the constraint-error remap in the charge adapters so
only missing foreign key violations become the “resource does not exist”
precondition. Update the `Charge` mapping logic in `charge.go` (and the matching
flat-fee and usage-based adapter code) to distinguish foreign-key failures from
other `db.IsConstraintError(err)` cases, and keep uniqueness or other constraint
errors flowing through their original handling instead of converting them in
`NewGenericPreConditionFailedError`.
---
Nitpick comments:
In `@openmeter/billing/charges/service/create.go`:
- Around line 73-103: The tax-code validation in validateTaxCodesExist currently
performs one GetTaxCode lookup per distinct taxCodeID, creating linear round
trips on the create path. Refactor this logic to batch the existence check for
all collected tax codes at once using the existing service/repository layer,
then map missing IDs back to the same tax_code_not_found validation error while
preserving the current deduping and empty-ID handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f50692ac-81b6-4a33-b9f3-4b3615957c76
📒 Files selected for processing (6)
openmeter/billing/charges/charge.goopenmeter/billing/charges/creditpurchase/adapter/charge.goopenmeter/billing/charges/flatfee/adapter/charge.goopenmeter/billing/charges/service/create.goopenmeter/billing/charges/usagebased/adapter/charge.gotest/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- test/credits/creditgrant_test.go
76987b9 to
7c9be16
Compare
Summary by CodeRabbit
Conflictas an additional possible response outcome.