fix(catalog): variant customize inherits base plan entitlement ids - #2300
Merged
Conversation
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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by cubic
Fixes duplicate-key errors when variant customizations inherit unchanged base items by stripping base plan
entitlement_id/price_idbefore applying changes. Variants and previews now mint their own entitlement and price rows, so catalog.update and re-push succeed.stripPlanRowIdsbeforeapplyDiffToVariantPlanin both update and preview paths to avoid reusing base plan row IDs.Written for commit e006600. Summary will update on new commits.
Greptile Summary
This PR fixes a duplicate-key constraint violation that occurred when
catalog.updatewas called with a variant that customized only some base-plan items while inheriting others unchanged. The root cause was thatincomingBasePlan(built from the base product's API response) carries internalentitlement_idandprice_idfields; when the customized plan was built withapplyDiffToVariantPlan, the unchanged (inherited) items still held those base-plan row IDs, causing anINSERTcollision on re-use.stripBasePlanRowIdsis introduced inupdateVariants.tsand applied afterapplyDiffToVariantPlan, clearingentitlement_idandprice_idfrom both the top-levelpriceand allitemsbefore the plan is persisted as the variant's own rows.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:
stripBasePlanRowIdsis called in every placebuildVariantTargetPlanis 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
stripBasePlanRowIdshelper and wrapsapplyDiffToVariantPlanoutput with it inbuildVariantTargetPlan; fix is applied in both the selected-variant and newly-created-variant code paths.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 ✓]%%{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 ✓]Reviews (1): Last reviewed commit: "fix(catalog): variant customize inherits..." | Re-trigger Greptile