fix(order): don't recreate past-version shipping method adjustments on order change#16029
Conversation
…n order change An existing shipping method keeps an adjustment row per order version, so its adjustments relation returns one per past version. Applying a change copied each to the new version and hit the unique (version, shipping_method_id) constraint, crashing return receipt on orders with a shipping-method adjustment.
🦋 Changeset detectedLatest commit: fee4df9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 79 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Well-scoped fix for issue #15959: applyChangesToOrder re-created shipping-method adjustments from all past versions when bumping the order version, hitting the unique (version, shipping_method_id) index. The fix carries only the current version's adjustments forward (new methods pass through as-is), which is correct given the model's unique index. Changeset added, template complete, linked to a verified issue, and a new integration test reproduces the crash and passes with the fix. No security, performance, or correctness concerns found. Triggered by: new PR opened |
|
@apoorva-01 can you resolve the merge conflict? |
Summary
What — Receiving a return on an order with a shipping-method adjustment (shipping promo) no longer crashes with
Order shipping method adjustment with version: N ... already exists. Fixes #15959.Why — A shipping method keeps one adjustment row per order version, so its
adjustmentsrelation returns one per past version. Receiving a return bumps the version andapplyChangesToOrderre-created all of them, so the duplicate(version, shipping_method_id)hit the unique index. Items are version-scoped, shipping methods aren't.How — Carry only the current version's adjustments forward. New methods pass through as-is.
Filtered at apply time. Could also fix it upstream on the relation load, happy to switch if you'd rather.
Testing — New test in
create-complete-return.spec.ts: throws without the fix, passes with it. RMA flows + order/return/fulfillment specs green.Checklist