Repository navigation
fix(productcatalog): make PUT /plans/{planId}/addons/{planAddonId} replace labels - #4969
tothandras wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe plan-addon update path now treats omitted labels as empty metadata. The adapter clears persisted metadata, while annotations remain unchanged when omitted. Creation now persists metadata. Tests verify creation and update behavior. ChangesPlan addon label replacement
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change makes plan-addon PUT requests replace labels, including clearing omitted labels, while preserving server-managed annotations. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ 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 |
643da63 to
f2d87ee
Compare
…place labels
PUT is a replace, but omitting `labels` on a plan-addon update kept the stored
labels. Two layers each treated nil as "no change": the v3 handler only populated
Metadata when the field was present, and the adapter only called SetMetadata when
the pointer was non-nil.
Always hand the service a metadata value (empty included) and switch the adapter
to the generated SetOrClear helper. Equal() now compares an omitted field against
the stored value so the no-op short-circuit does not skip a legitimate clear.
Annotations stay out of the replace surface: they are server-managed, are not part
of the plan-addon representation, and a client cannot send them.
Note that `name` and `description` in the request body remain inert -- the
plan-addon entity stores neither -- so they are still not mapped. That is a
separate API-shape question from the replace semantics fixed here.
Affects v1 too, which shares this adapter behind
PUT /api/v1/plans/{planId}/addons/{planAddonId}.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R7aYus5cbiqf48bnJkrQDv
f2d87ee to
6ae9c77
Compare
CreatePlanAddon never wrote the metadata column, so labels sent on create were silently dropped and the replace e2e test could not observe a clear. The existing create-input assertion now exercises metadata round-trip.
Overview
Omitting
labelson a plan-addon update kept the stored labels. Two layers each independently treated nil as "no change", so fixing either one alone would not have been enough:req.Metadatawhenbody.Labels != nil;SetMetadatawhenparams.Metadata != nil.Now the handler always hands the service a metadata value (empty included), and the adapter uses the generated
SetOrClearhelper.Equal()compares an omitted field against the stored value so the no-op short-circuit does not skip a legitimate clear.Notes for reviewer
Annotations are deliberately excluded from the replace. They are server-managed and are not part of the plan-addon representation at all —
ToAPIPlanAddonreturns onlylabels— so a client has no way to send them and a PUT has no business clearing them.One thing this PR does not fix, on purpose.
UpsertPlanAddonRequestcarriesnameanddescription, but the plan-addon entity stores neither (PlanAddonMetais metadata + annotations +from_plan_phase+max_quantity) andPlanAddonreturns neither. They are inert write-only fields today, and they were inert before this change too. Making the request body honest about that is a separate API-shape question from the replace semantics here, so I left it alone rather than quietly widening the scope — flagging it in case you want it tracked.This affects v1 as well —
PUT /api/v1/plans/{planId}/addons/{planAddonId}shares this adapter.Tests:
go test ./openmeter/productcatalog/planaddon/... ./api/v3/handlers/plans/...against Postgres. E2ETestV3PlanAddonUpdateClearsOmittedLabelscovers create → PUT-omitting → GET-cleared over HTTP (compiles and vets; not run here — needs a live server).Generated by Claude Code
Summary by CodeRabbit
Greptile Summary
This PR aligns plan-add-on label handling with PUT replacement semantics while preserving server-managed annotations.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Reviews (3): Last reviewed commit: "fix(productcatalog): persist plan add-on..." | Re-trigger Greptile
Update (review round 1)
CreatePlanAddonnever wrote the metadata column, which is why the e2e test failed in CI at therequire.NotEmpty(created.Labels)precondition. Create now persists metadata, and the existing create-input assertion exercises the round-trip (the service test input now carries metadata).TestV3PlanAddon*(all of them, including the new clear test) verified against a live local stack built from this branch.