Skip to content

fix: allow entitlement and subscription creation if customer has no subjects assigned - #3642

Merged
GAlexIHU merged 1 commit into
mainfrom
fix/allow-subs-create-with-no-subjects
Nov 27, 2025
Merged

GAlexIHU merged 1 commit into
mainfrom
fix/allow-subs-create-with-no-subjects

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • Bug Fixes

    • Subscriptions can now be created successfully even when Customer UsageAttribution contains no subjects.
  • Tests

    • Added test coverage for subscription creation with empty UsageAttribution, validating both standard and custom subscription flows with proper status assertions.

✏️ Tip: You can customize this high-level summary in your review settings.

@GAlexIHU
GAlexIHU requested a review from a team as a code owner November 27, 2025 14:10
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Nov 27, 2025
@GAlexIHU
GAlexIHU enabled auto-merge (squash) November 27, 2025 14:10
@coderabbitai

coderabbitai Bot commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds validation for empty UsageAttribution subject keys and improves how subscriptions handle customers without subject assignments. Changes include a new Validate() method for CustomerUsageAttribution, refactored validation in entitlement logic, and expanded test coverage for subscription creation scenarios.

Changes

Cohort / File(s) Summary
Test Coverage
e2e/productcatalog_test.go
Adds third customer to TestPlan setup and introduces new test subcase validating subscription creation when Customer.UsageAttribution lacks subject keys
Validation Refactoring
openmeter/entitlement/entitlement.go
Delegates UsageAttribution validation to CustomerUsageAttribution.Validate() method instead of inline checks
New Validation Method
openmeter/streaming/query_params.go
Adds Validate() error method to CustomerUsageAttribution type to enforce non-empty ID field

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the new Validate() method logic on CustomerUsageAttribution to confirm the ID validation is appropriate
  • Check the refactored validation call in entitlement.go to ensure error handling behavior matches the original inline checks
  • Verify test cases adequately cover the empty SubjectKeys scenario across both test locations

Possibly related PRs

Suggested reviewers

  • chrisgacsal
  • turip
  • tothandras

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change—allowing entitlement and subscription creation when customers have no subjects assigned, which is directly supported by the code changes and test additions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/allow-subs-create-with-no-subjects

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
openmeter/entitlement/entitlement.go (1)

197-199: Nice centralization of usage-attribution validation

Delegating to c.UsageAttribution.Validate() keeps the entitlement validation focused and removes the old implicit coupling to non-empty subject keys, which is what was blocking customers with no subjects. This is a clean, future-proof spot to grow any additional attribution rules.

Looks good as-is.

e2e/productcatalog_test.go (2)

89-113: customer3 setup correctly models the “no subjects” scenario (one small robustness nit)

Creating customer3 with UsageAttribution.SubjectKeys: []string{} is a nice, explicit way to cover the “no subjects assigned” path, and the assertions around the response look solid.

One small robustness thought: later in this test you also create another “Test Customer 3” with the same email but different usage attribution. If the backend ever enforces uniqueness on primary email or key semantics change, that could make this e2e flaky. You might consider giving one of them a slightly different key/email (e.g. [email protected]) to decouple the scenarios.


523-552: New subscription test nicely covers the empty-subjects case

This subtest does a good job of proving the fix: it uses customer3 (no subjects), goes through the same timing/billing-anchor flow as the existing custom-subscription test, and asserts we still get a 201, an active subscription, and no attached plan. That’s exactly the regression guard you want here.

Only minor polish you might consider (optional): the failure message on require.Nil(t, err, "received the following err: %w", err) could just use %v or a plain string to avoid depending on %w formatting behavior, but functionally the test is fine.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc4e6bb and faa56fa.

📒 Files selected for processing (3)
  • e2e/productcatalog_test.go (3 hunks)
  • openmeter/entitlement/entitlement.go (1 hunks)
  • openmeter/streaming/query_params.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

⚙️ CodeRabbit configuration file

**/*.go: In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.

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.

Files:

  • openmeter/entitlement/entitlement.go
  • openmeter/streaming/query_params.go
  • e2e/productcatalog_test.go
**/*_test.go

⚙️ CodeRabbit configuration file

**/*_test.go: Make sure the tests are comprehensive and cover the changes. Keep a strong focus on unit tests and in-code integration tests.
When appropriate, recommend e2e tests for critical changes.

Files:

  • e2e/productcatalog_test.go
🧬 Code graph analysis (2)
openmeter/streaming/query_params.go (5)
openmeter/customer/customer.go (1)
  • CustomerUsageAttribution (200-202)
api/api.gen.go (1)
  • CustomerUsageAttribution (2411-2415)
openmeter/billing/invoice.go (1)
  • CustomerUsageAttribution (609-609)
pkg/models/validator.go (1)
  • Validate (16-26)
pkg/models/errors.go (1)
  • NewGenericValidationError (138-140)
e2e/productcatalog_test.go (2)
api/api.gen.go (7)
  • CustomerUsageAttribution (2411-2415)
  • SubscriptionTiming (7550-7552)
  • SubscriptionCreate (7266-7268)
  • CustomSubscriptionCreate (2204-2220)
  • CustomerKey (2352-2354)
  • SubscriptionStatusActive (812-812)
  • Plan (5963-6025)
openmeter/subscription/state.go (1)
  • SubscriptionStatusActive (16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Lint
  • GitHub Check: Migration Checks
  • GitHub Check: Test
  • GitHub Check: Code Generators
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
openmeter/streaming/query_params.go (1)

87-93: Validation looks good and matches the “no subjects” requirement

Centralizing the check on ID here and not enforcing any constraint on SubjectKeys lines up nicely with the API contract that subject keys can be empty while still requiring a concrete customer identifier. The use of models.NewGenericValidationError also keeps this consistent with the rest of the validation layer.

Nothing to change from my side here.

e2e/productcatalog_test.go (1)

31-31: Comment update matches the new setup

The comment now correctly reflects that you’re working with three customers in this test, which helps keep the long test readable.

@GAlexIHU
GAlexIHU merged commit fb16717 into main Nov 27, 2025
@GAlexIHU
GAlexIHU deleted the fix/allow-subs-create-with-no-subjects branch November 27, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants