Skip to content

fix(order): don't recreate past-version shipping method adjustments on order change#16029

Open
apoorva-01 wants to merge 1 commit into
medusajs:developfrom
apoorva-01:fix/receive-return-shipping-adjustment-version
Open

fix(order): don't recreate past-version shipping method adjustments on order change#16029
apoorva-01 wants to merge 1 commit into
medusajs:developfrom
apoorva-01:fix/receive-return-shipping-adjustment-version

Conversation

@apoorva-01

Copy link
Copy Markdown

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 adjustments relation returns one per past version. Receiving a return bumps the version and applyChangesToOrder re-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

  • Changeset added
  • Covered by tests
  • Verified locally
  • Linked the issue

…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.
@apoorva-01
apoorva-01 requested a review from a team as a code owner July 14, 2026 09:26
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fee4df9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 79 packages
Name Type
@medusajs/order Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

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

@medusa-os-bot

medusa-os-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

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

@shahednasser shahednasser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@shahednasser

Copy link
Copy Markdown
Member

@apoorva-01 can you resolve the merge conflict?

@NicolasGorga NicolasGorga 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.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: receiving a return crashes with duplicate order_shipping_method_adjustment version when the order has a shipping-method (promotion) adjustment

3 participants