ref(billing): Add quota_config_mapping for proto/sentry QuotaConfig conversion#119133
Conversation
…onversion Add conversion utilities between proto QuotaConfig and sentry QuotaConfig to support migrating billing platform services from dataclass prototypes to protobufs.
…fig mapping DataCategory() and QuotaScope() raise ValueError for unmapped proto enum values that don't correspond to valid sentry enum members. Catch these errors gracefully: skip unknown categories and fall back to ORGANIZATION scope, logging warnings for observability. Co-Authored-By: Claude Opus 4.6 <noreply@example.com>
| else QuotaScope.ORGANIZATION | ||
| ) | ||
| except ValueError: | ||
| logger.warning( |
There was a problem hiding this comment.
should log an exception
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f1a1a04. Configure here.
|
|
||
| return QuotaConfig( | ||
| id=proto_quota.id or None, | ||
| categories=categories, |
There was a problem hiding this comment.
Dropped categories widen quota scope
Medium Severity
In proto_to_sentry_quota_config, proto categories that fail DataCategory construction are skipped. If every category is skipped, the resulting QuotaConfig has an empty category set, which Sentry treats as applying the quota to all data—not a category-specific quota—so enforcement can broaden incorrectly.
Reviewed by Cursor Bugbot for commit f1a1a04. Configure here.
There was a problem hiding this comment.
Fixed in ba82e25 — proto_to_sentry_quota_config now returns None when the proto had categories but all were unmapped, preventing the empty category set from broadening the quota to all data.
— Claude Code
Address Cursor Bugbot feedback: if a proto QuotaConfig had categories but all were unmapped, the resulting empty category set would broaden the quota to apply to all data. Now returns None in that case. Also adds comprehensive tests for both conversion directions. Co-Authored-By: Claude Opus 4.6 <noreply@example.com>
Cast raw int values to proper proto ValueType types to satisfy mypy. Co-Authored-By: Claude Opus 4.6 <noreply@example.com>
There was a problem hiding this comment.
Did you intentionally place this module at the top of services/?
Did you have services/quotas/ in mind?
Relocate quota_config_mapping.py and its tests into a new quota/ package under services/ for better organization.


Summary
sentry_to_proto_quota_config()andproto_to_sentry_quota_config()conversion utilities insentry/billing/platform/services/quota_config_mapping.pycategory_mapping.pybut operate at the QuotaConfig levelQuotasServiceandContractBudgetEnforcerfrom dataclass prototypes to protobufsTest plan