Skip to content

fix(catalog): variant customize inherits base plan entitlement ids - #2300

Merged
og2701 merged 2 commits into
devfrom
owen/variant-inherited-entitlement-ids
Jul 20, 2026
Merged

fix(catalog): variant customize inherits base plan entitlement ids#2300
og2701 merged 2 commits into
devfrom
owen/variant-inherited-entitlement-ids

Conversation

@og2701

@og2701 og2701 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary by cubic

Fixes duplicate-key errors when variant customizations inherit unchanged base items by stripping base plan entitlement_id/price_id before applying changes. Variants and previews now mint their own entitlement and price rows, so catalog.update and re-push succeed.

  • Bug Fixes
    • Use stripPlanRowIds before applyDiffToVariantPlan in both update and preview paths to avoid reusing base plan row IDs.
    • Added integration test covering inherit-one/replace-one and a repeat push.

Written for commit e006600. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR fixes a duplicate-key constraint violation that occurred when catalog.update was called with a variant that customized only some base-plan items while inheriting others unchanged. The root cause was that incomingBasePlan (built from the base product's API response) carries internal entitlement_id and price_id fields; when the customized plan was built with applyDiffToVariantPlan, the unchanged (inherited) items still held those base-plan row IDs, causing an INSERT collision on re-use.

  • Bug fixesstripBasePlanRowIds is introduced in updateVariants.ts and applied after applyDiffToVariantPlan, clearing entitlement_id and price_id from both the top-level price and all items before the plan is persisted as the variant's own rows.
  • Bug fixes — An integration test (catalog-variant-inherited-item.test.ts) reproduces the exact failure scenario and validates both the first push and an idempotent re-push.

Confidence Score: 5/5

Safe to merge — the change is a narrow, well-scoped fix that strips two internal fields from the variant's target plan before insertion, with no downstream consumers of those fields on the variant path.

The fix is minimal and correct: stripBasePlanRowIds is called in every place buildVariantTargetPlan is used (both existing and newly-created variants), the null-price guard is in place, and the accompanying integration test reproduces the exact failure and validates idempotent re-push. No unrelated code is touched.

No files require special attention.

Important Files Changed

Filename Overview
server/src/internal/product/actions/updateVariants/updateVariants.ts Adds stripBasePlanRowIds helper and wraps applyDiffToVariantPlan output with it in buildVariantTargetPlan; fix is applied in both the selected-variant and newly-created-variant code paths.
server/tests/integration/crud/catalog/catalog-variant-inherited-item.test.ts New integration test covering the exact regression scenario: one item customized, one inherited; validates no entitlement-ID collision on both the first and second push.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[catalog.update called with variant customize] --> B[fullProductToApiPlanV1\nbuilds incomingBasePlan\nwith entitlement_id & price_id]
    B --> C[applyDiffToVariantPlan\napplies customize diff\ninherited items keep base IDs]
    C --> D{Before fix}
    D -->|entitlement_id carried over| E[INSERT variant entitlement\nusing base plan's ID\n→ duplicate key constraint!]
    C --> F{After fix}
    F --> G[stripBasePlanRowIds\nremoves entitlement_id & price_id\nfrom price and all items]
    G --> H[INSERT variant entitlement\nwith fresh generated ID\n→ success ✓]
    H --> I[Re-push also succeeds ✓]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[catalog.update called with variant customize] --> B[fullProductToApiPlanV1\nbuilds incomingBasePlan\nwith entitlement_id & price_id]
    B --> C[applyDiffToVariantPlan\napplies customize diff\ninherited items keep base IDs]
    C --> D{Before fix}
    D -->|entitlement_id carried over| E[INSERT variant entitlement\nusing base plan's ID\n→ duplicate key constraint!]
    C --> F{After fix}
    F --> G[stripBasePlanRowIds\nremoves entitlement_id & price_id\nfrom price and all items]
    G --> H[INSERT variant entitlement\nwith fresh generated ID\n→ success ✓]
    H --> I[Re-push also succeeds ✓]
Loading

Reviews (1): Last reviewed commit: "fix(catalog): variant customize inherits..." | Re-trigger Greptile

@og2701
og2701 requested review from ay-rod and johnyeocx as code owners July 20, 2026 09:03
@capy-ai

capy-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Capy auto-review is paused for this organization because the usage-cycle auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
checkout Ignored Ignored Jul 20, 2026 9:17am
landing-page Ignored Ignored Jul 20, 2026 9:17am

Request Review

@vercel
vercel Bot temporarily deployed to Preview – autumn-vite July 20, 2026 09:17 Inactive
@og2701
og2701 merged commit 92e22f3 into dev Jul 20, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant