Repository navigation
fix: plan add-on assignment service - #2704
Conversation
📝 WalkthroughWalkthroughThis change removes explicit validation calls from mapping functions that convert database rows into domain model objects across several modules. Instead of invoking Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
openmeter/productcatalog/planaddon/service/planaddon.go (2)
208-216: 👍 Good addition – but consider using a specific validation error instead of “not‑found”The newly added plan checks prevent deleting an assignment when the plan is deleted or not in
Draft/Scheduled– great!
However, turning validation failures into aGenericNotFoundErrormay mislead API consumers (they will assume the resource is missing). AGenericValidationError(or a new domain‑specific code) would communicate the situation more accurately.If backwards‑compatibility requires the “not‑found” semantics, add a short comment explaining the rationale.
336-336: Typo in error message (“udpate”)- return nil, models.NewGenericNotFoundError( - fmt.Errorf("failed to udpate plan add-on assignment ... + return nil, models.NewGenericNotFoundError( + fmt.Errorf("failed to update plan add-on assignment ...A minor typo, but worth fixing to keep logs and error texts professional.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
openmeter/productcatalog/addon/adapter/mapping.go(0 hunks)openmeter/productcatalog/plan/adapter/mapping.go(0 hunks)openmeter/productcatalog/planaddon/adapter/mapping.go(0 hunks)openmeter/productcatalog/planaddon/service/planaddon.go(6 hunks)
💤 Files with no reviewable changes (3)
- openmeter/productcatalog/addon/adapter/mapping.go
- openmeter/productcatalog/planaddon/adapter/mapping.go
- openmeter/productcatalog/plan/adapter/mapping.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
openmeter/productcatalog/planaddon/service/planaddon.go (6)
openmeter/productcatalog/plan/validators.go (2)
IsPlanDeleted(13-21)HasPlanStatus(23-31)pkg/clock/clock.go (1)
Now(14-21)openmeter/productcatalog/addon/validators.go (2)
IsAddonDeleted(13-21)HasAddonStatus(23-31)openmeter/productcatalog/plan/plan.go (1)
Plan(18-30)pkg/models/error.go (1)
NewGenericNotFoundError(38-40)openmeter/productcatalog/addon/addon.go (1)
Addon(15-23)
⏰ Context from checks skipped due to timeout of 90000ms (10)
- GitHub Check: Test
- GitHub Check: Quickstart
- GitHub Check: Migration Checks
- GitHub Check: Lint
- GitHub Check: E2E
- GitHub Check: Developer environment
- GitHub Check: CI
- GitHub Check: Build
- GitHub Check: Commit hooks
- GitHub Check: Analyze (go)
| if err = planAddon.Plan.ValidateWith( | ||
| plan.IsPlanDeleted(clock.Now()), | ||
| plan.HasPlanStatus(productcatalog.PlanStatusDraft, productcatalog.PlanStatusScheduled), | ||
| ); err != nil { | ||
| return nil, models.NewGenericNotFoundError( | ||
| fmt.Errorf("failed to udpate plan add-on assignment [namespace=%s plan.id=%s addon.id=%s]: %w", | ||
| params.Namespace, params.PlanID, params.AddonID, err), | ||
| ) | ||
| } |
There was a problem hiding this comment.
Missing Add‑on state validation on Update
UpdatePlanAddon used to reload and validate the add‑on; now it only validates the plan.
An add‑on can become deleted or move out of Active status after the assignment was created, so updating the assignment may silently succeed while referencing an invalid add‑on.
Consider restoring the validation, re‑using the already loaded planAddon.Addon:
+ // Validate add‑on
+ if err = planAddon.Addon.ValidateWith(
+ addon.IsAddonDeleted(clock.Now()),
+ addon.HasAddonStatus(productcatalog.AddonStatusActive),
+ ); err != nil {
+ return nil, models.NewGenericNotFoundError(
+ fmt.Errorf("failed to update plan add‑on assignment [namespace=%s plan.id=%s addon.id=%s]: %w",
+ params.Namespace, params.PlanID, params.AddonID, err),
+ )
+ }This keeps business rules consistent across Create/Update paths.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
openmeter/productcatalog/planaddon/service/planaddon.go (2)
331-339: Typo in log/error messages (“udpate”) and missing capitalisationThere is a minor typo that appears twice (
udpate). Fixing it improves diagnostics and avoids search discrepancies.- fmt.Errorf("failed to udpate plan add-on assignment [namespace=%s plan.id=%s addon.id=%s]: %w", + fmt.Errorf("failed to update plan add-on assignment [namespace=%s plan.id=%s addon.id=%s]: %w",Search the file for the same misspelling to keep messages consistent.
341-354: Potential double conversion of domain models
planAddon.Plan.AsProductCatalogPlan()andplanAddon.Addon.AsProductCatalogAddon()are called althoughplanAddonwas originally produced byadapter.GetPlanAddon, which (per the refactor) now already yields validatedproductcatalog.Plan/Addonobjects. The extra conversion:
- Wastes a small amount of CPU/allocations.
- Risks silently diverging if conversion helpers evolve.
If
planAddon.Plan/Addonare already the desired types, you can assign them directly:- Plan: planAddon.Plan.AsProductCatalogPlan(), - Addon: planAddon.Addon.AsProductCatalogAddon(), + Plan: planAddon.Plan, + Addon: planAddon.Addon,Please verify the concrete types returned by the adapter to avoid accidental interface narrowing.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
openmeter/productcatalog/addon/adapter/mapping.go(0 hunks)openmeter/productcatalog/plan/adapter/mapping.go(0 hunks)openmeter/productcatalog/planaddon/adapter/mapping.go(0 hunks)openmeter/productcatalog/planaddon/service/planaddon.go(6 hunks)
💤 Files with no reviewable changes (3)
- openmeter/productcatalog/planaddon/adapter/mapping.go
- openmeter/productcatalog/addon/adapter/mapping.go
- openmeter/productcatalog/plan/adapter/mapping.go
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: E2E
- GitHub Check: Developer environment
- GitHub Check: CI
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
openmeter/productcatalog/planaddon/service/planaddon.go (1)
208-216: Validation failure is translated to “not‑found” — is that intentional?When the plan linked to the assignment is deleted or in an immutable status, the code maps the validation error to
models.NewGenericNotFoundError. From a consumer’s standpoint this is misleading: the assignment exists, but cannot be deleted because the plan is locked, which is a 409‑Conflict‑style situation rather than 404‑Not‑Found.Double‑check the desired API semantics; if the goal is to hide resource existence for permission reasons that should be documented. Otherwise consider surfacing a
ConflictorValidationerror instead.
Overview
Fix validation for assignment udpate/delete operations.
Summary by CodeRabbit