Repository navigation
fix: plan ratecard mapping - #4516
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 (2)
📝 WalkthroughWalkthroughFeature 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. ChangesRate Card Feature Edge Loading
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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 |
Greptile SummaryThis PR fixes a panic/error in ratecard mapping when a ratecard row has
Confidence Score: 3/5Safe 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
|
| 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) | ||
| } |
There was a problem hiding this comment.
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!
| // FIXME(chrisgacsal): temporary fix until data is migrated | ||
| if err == nil && ratecardFeature != nil { | ||
| meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key) | ||
| } |
There was a problem hiding this comment.
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.
| // FIXME(chrisgacsal): temporary fix until data is migrated | ||
| if err == nil && ratecardFeature != nil { | ||
| meta.SetFeature(&ratecardFeature.ID, &ratecardFeature.Key) | ||
| } |
There was a problem hiding this comment.
Fix ratecard mapping for ratecards where there is no hard reference to feature.
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
Release Notes