Skip to content

fix: plan ratecard mapping - #4516

Merged
chrisgacsal merged 1 commit into
mainfrom
fix/plan-list
Jun 12, 2026
Merged

chrisgacsal merged 1 commit into
mainfrom
fix/plan-list

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fix ratecard mapping for ratecards where there is no hard reference to feature.

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced robustness of product catalog feature loading to gracefully handle cases where feature data is unavailable, preventing system failures while maintaining core functionality.

@chrisgacsal chrisgacsal self-assigned this Jun 12, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner June 12, 2026 10:28
@chrisgacsal chrisgacsal added the release-note/bug-fix Release note: Bug Fixes label Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f4019a9b-0925-4878-9a7f-8212ba950799

📥 Commits

Reviewing files that changed from the base of the PR and between c345f9c and 6e1af9e.

📒 Files selected for processing (2)
  • openmeter/productcatalog/addon/adapter/mapping.go
  • openmeter/productcatalog/plan/adapter/mapping.go

📝 Walkthrough

Walkthrough

Feature edge loading in the addon and plan rate card mappers is made optional rather than required. When the feature edge is missing or fails to load, feature metadata fields now remain unset instead of causing the entire mapping operation to fail.

Changes

Rate Card Feature Edge Loading

Layer / File(s) Summary
Graceful feature edge loading in addon and plan rate card mappers
openmeter/productcatalog/addon/adapter/mapping.go, openmeter/productcatalog/plan/adapter/mapping.go
Both FromAddonRateCardRow and fromPlanRateCardRow now conditionally set rate card feature metadata only when FeaturesOrErr() succeeds with a non-nil feature object, replacing the previous hard-error approach with graceful fallback when feature edges aren't available.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • openmeterio/openmeter#4352: Updates RateCardMeta.Validate() to check if a feature exists via the new HasFeature() method, which complements this PR's conditional feature assignment in mappers.
  • openmeterio/openmeter#4338: Directly overlaps with the same rate card feature resolution code paths in both adapter mapping files.
  • openmeterio/openmeter#4268: Touches the same FeaturesOrErr() loading logic to defensively backfill RateCardMeta.FeatureKey when needed.

Suggested reviewers

  • tothandras
  • turip
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: plan ratecard mapping' directly describes the main change: fixing ratecard mapping logic in plan-related code, which aligns with both file changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/plan-list

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.

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a panic/error in ratecard mapping when a ratecard row has FeatureID/FeatureKey set but the feature entity can no longer be loaded from the database (e.g. after a data migration removes orphaned feature references). Both the plan and addon adapters receive the same change.

  • The guard if err == nil && ratecardFeature != nil replaces the hard error return so that mapping succeeds even when the feature edge is absent; FeatureID/FeatureKey remain set on the meta from the row columns.
  • Both files leave the original code as block comments rather than removing it, and the FIXME note indicates the workaround is intentionally temporary.

Confidence Score: 3/5

Safe to merge if all callers always eager-load the features edge; risky if any code path omits the join, since that bug is now silently hidden.

Both adapters now swallow NotLoadedError — indicating the query never joined the feature edge — the same way they swallow NotFoundError. A missing eager-load would silently produce a RateCardMeta with stale IDs and no observable signal, making regression hard to catch.

Both openmeter/productcatalog/plan/adapter/mapping.go and openmeter/productcatalog/addon/adapter/mapping.go warrant a second look at the error-handling logic.

Important Files Changed

Filename Overview
openmeter/productcatalog/plan/adapter/mapping.go Changes fromPlanRateCardRow to skip SetFeature when the feature edge cannot be loaded, but the fix conflates NotFoundError and NotLoadedError, leaving a query-layer bug silently undetectable.
openmeter/productcatalog/addon/adapter/mapping.go Mirrors the plan adapter change in FromAddonRateCardRow — same concerns about silent suppression of both error classes apply here.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["fromPlanRateCardRow / FromAddonRateCardRow"] --> B{FeatureID or FeatureKey set on row?}
    B -- No --> E[Skip feature edge load]
    B -- Yes --> C["FeaturesOrErr()"]
    C --> D1{"err == nil AND ratecardFeature != nil?"}
    D1 -- Yes --> F["meta.SetFeature(id, key)"]
    D1 -- No --> G["Silent skip — meta keeps FeatureID/FeatureKey from row"]
    G --> H{Which error?}
    H -- NotFoundError --> I["Feature deleted/missing (data-migration scenario)"]
    H -- NotLoadedError --> J["Edge never joined in query (potential query bug, now silent)"]
    F --> K[Continue mapping]
    E --> K
    I --> K
    J --> K
Loading

Fix All in Claude Code

Reviews (1): Last reviewed commit: "fix: plan ratecard mapping" | Re-trigger Greptile

Comment on lines 303 to 313
ratecardFeature, err := r.Edges.FeaturesOrErr()
if err != nil {
return nil, errors.New("feature is not loaded for ratecard")
//if err != nil {
// return nil, errors.New("feature is not loaded for ratecard")
//}
//
//meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key)

// FIXME(chrisgacsal): temporary fix until data is migrated
if err == nil && ratecardFeature != nil {
meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key)
}

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.

P2 Commented-out code left in place

The old logic is preserved as comments rather than removed. This is present in both plan/adapter/mapping.go and addon/adapter/mapping.go. Leaving commented-out code in production makes it harder to reason about what the current behaviour actually is, and diff noise accumulates over time. The new if err == nil && ratecardFeature != nil block alone is sufficient to document the intent; the old lines add no value.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Comment on lines +310 to 313
// FIXME(chrisgacsal): temporary fix until data is migrated
if err == nil && ratecardFeature != nil {
meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key)
}

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.

P1 Silent suppression conflates two distinct error cases

FeaturesOrErr() returns two semantically different errors: NotFoundError (edge was loaded, feature was deleted from the DB) and NotLoadedError (the query never joined the edge at all). This fix treats them identically. For the NotFoundError case, silently keeping the stored IDs is a reasonable migration workaround. For the NotLoadedError case, the query itself may be missing an eager-load, and swallowing that error will silently produce a RateCardMeta whose FeatureID/FeatureKey are set but were never cross-checked against the actual entity — a potential query-layer bug that will now go undetected.

Consider at minimum logging a warning on NotLoadedError so the discrepancy is observable, or returning an error only for that case while allowing NotFoundError to fall through.

Fix in Claude Code

Comment on lines +109 to 112
// FIXME(chrisgacsal): temporary fix until data is migrated
if err == nil && ratecardFeature != nil {
meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key)
}

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.

P1 Same silent-suppression concern as the plan adapter

The identical FIXME block in the addon adapter has the same issue: it swallows both NotLoadedError and NotFoundError without distinction. See the corresponding comment on plan/adapter/mapping.go for details.

Fix in Claude Code

@chrisgacsal
chrisgacsal enabled auto-merge (squash) June 12, 2026 10:57
@chrisgacsal
chrisgacsal merged commit fda362f into main Jun 12, 2026
24 of 27 checks passed
@chrisgacsal
chrisgacsal deleted the fix/plan-list branch June 12, 2026 10:57
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