Skip to content

fix(productcatalog): make PUT /plans/{planId}/addons/{planAddonId} replace labels - #4969

Closed
tothandras wants to merge 2 commits into
mainfrom
claude/v3-put-replace-plan-addons
Closed

tothandras wants to merge 2 commits into
mainfrom
claude/v3-put-replace-plan-addons

Conversation

@tothandras

@tothandras tothandras commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Omitting labels on 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:

  • the v3 handler only set req.Metadata when body.Labels != nil;
  • the adapter only called SetMetadata when params.Metadata != nil.

Now the handler always hands the service a metadata value (empty included), and the adapter uses the generated SetOrClear helper. 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 — ToAPIPlanAddon returns only labels — 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. UpsertPlanAddonRequest carries name and description, but the plan-addon entity stores neither (PlanAddonMeta is metadata + annotations + from_plan_phase + max_quantity) and PlanAddon returns 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. E2E TestV3PlanAddonUpdateClearsOmittedLabels covers create → PUT-omitting → GET-cleared over HTTP (compiles and vets; not run here — needs a live server).


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Updating a plan add-on without labels now clears existing labels instead of preserving them.
    • Label removal is consistently saved and reflected in subsequent requests.
    • Metadata updates are now applied consistently, including when metadata is omitted.
    • Creating a plan add-on now correctly persists its metadata.
    • Annotations remain unchanged unless explicitly updated.

Greptile Summary

This PR aligns plan-add-on label handling with PUT replacement semantics while preserving server-managed annotations.

  • Always maps omitted v3 labels to an explicit empty metadata target.
  • Persists metadata during plan-add-on creation and sets or clears it during updates.
  • Updates equality behavior so legitimate label clears are not skipped.
  • Adds service and end-to-end coverage for metadata persistence and omitted-label clearing.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
api/v3/handlers/plans/planaddons/update.go Converts omitted labels into an explicit empty metadata value before invoking the service.
openmeter/productcatalog/planaddon/adapter/planaddon.go Persists metadata on creation and applies replacement semantics during updates while preserving annotations.
openmeter/productcatalog/planaddon/service.go Treats omitted update metadata as an empty target when evaluating whether an update is a no-op.
openmeter/productcatalog/planaddon/service/service_test.go Extends service coverage to verify plan-add-on metadata persistence.
e2e/planaddons_v3_test.go Adds HTTP-level coverage showing that a PUT omitting labels clears previously stored labels.

Reviews (3): Last reviewed commit: "fix(productcatalog): persist plan add-on..." | Re-trigger Greptile

Update (review round 1)

  • Create dropped labels entirely: the adapter's CreatePlanAddon never wrote the metadata column, which is why the e2e test failed in CI at the require.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).
  • E2E TestV3PlanAddon* (all of them, including the new clear test) verified against a live local stack built from this branch.

@tothandras
tothandras requested a review from a team as a code owner August 22, 2026 17:00
@coderabbitai

coderabbitai Bot commented Aug 22, 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 Plus

Run ID: 88820de6-2d8d-4c0b-a070-6dff78c4a4d8

📥 Commits

Reviewing files that changed from the base of the PR and between 30855c3 and 2a0cf04.

📒 Files selected for processing (5)
  • api/v3/handlers/plans/planaddons/update.go
  • e2e/planaddons_v3_test.go
  • openmeter/productcatalog/planaddon/adapter/planaddon.go
  • openmeter/productcatalog/planaddon/service.go
  • openmeter/productcatalog/planaddon/service/service_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Plan addon label replacement

Layer / File(s) Summary
Persist plan-addon creation metadata
openmeter/productcatalog/planaddon/adapter/planaddon.go, openmeter/productcatalog/planaddon/service/service_test.go
Plan-addon creation persists input metadata. The creation test supplies env=prod metadata.
Apply omitted-label replacement semantics
api/v3/handlers/plans/planaddons/update.go, openmeter/productcatalog/planaddon/service.go, openmeter/productcatalog/planaddon/adapter/planaddon.go
The update path converts omitted labels to empty metadata, compares omitted metadata as empty, and clears stored metadata. Omitted annotations remain unchanged.
Validate persisted label clearing
e2e/planaddons_v3_test.go
The end-to-end test verifies empty labels in the update response and after fetching the updated junction.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 2a0cf

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: galexihu, rolosp

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: PUT updates now replace omitted plan-addon labels instead of preserving them.
✨ 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 claude/v3-put-replace-plan-addons

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.

@tothandras
tothandras force-pushed the claude/v3-put-replace-plan-addons branch 2 times, most recently from 643da63 to f2d87ee Compare August 23, 2026 12:20
…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
@tothandras
tothandras force-pushed the claude/v3-put-replace-plan-addons branch from f2d87ee to 6ae9c77 Compare August 23, 2026 12:21
@tothandras tothandras added the release-note/bug-fix Release note: Bug Fixes label Aug 23, 2026
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.
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