Skip to content

fix: guard calculatedPriceSet to avoid 500 instead of 400 on missing …#15936

Open
Yashraj-Pradip-Haridas wants to merge 2 commits into
medusajs:developfrom
Yashraj-Pradip-Haridas:fix/500-instead-of-400-missing-price
Open

fix: guard calculatedPriceSet to avoid 500 instead of 400 on missing …#15936
Yashraj-Pradip-Haridas wants to merge 2 commits into
medusajs:developfrom
Yashraj-Pradip-Haridas:fix/500-instead-of-400-missing-price

Conversation

@Yashraj-Pradip-Haridas

@Yashraj-Pradip-Haridas Yashraj-Pradip-Haridas commented Jul 3, 2026

Copy link
Copy Markdown

Fixes #15932
…price

Summary

What — What changes are introduced in this PR?
Fixed a bug where adding a cart line item for a variant with no price in the cart's region threw an unhandled 500 TypeError instead of the intended 400 validation error.

Why — Why are these changes relevant or necessary?
References issue #15932; it's a real production bug that surfaces as an opaque error to storefront clients.

How — How have these changes been implemented?
Added a calculatedPriceSet guard to the price-assignment branch so the already-collected priceNotFound list is actually used, letting the existing MedusaError be thrown as intended.

Testing — How have these changes been tested, or how can the reviewer test the feature?
I added an integration test in integration-tests/http/tests/cart/store/cart.spec.ts, under the POST /store/carts/:id/line-items describe block:

should throw a 400 error instead of a 500 when adding a variant that has no price in the cart's currency

The test creates a product with a price only in usd, creates a cart scoped to a EUR region, then attempts to add the unpriced variant as a line item. It asserts the response is a 400 with type: "invalid_data", rather than an unhandled 500.
I verified the fix locally by running the test both before and after applying the change:

Before the fix (reverted): the request throws an unhandled 500 TypeError: Cannot read properties of undefined (reading 'calculated_amount'), and the test fails as expected.
After the fix: the request returns the intended 400 validation error, and the test passes.

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

@Yashraj-Pradip-Haridas Yashraj-Pradip-Haridas requested a review from a team as a code owner July 3, 2026 20:40
@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d3f78e5

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

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

Copy link
Copy Markdown

Thanks for the contribution! A few items need to be addressed before this can move forward:

The core fix is correct: adding the calculatedPriceSet guard prevents the TypeError (500) and lets the existing INVALID_DATA MedusaError (400) fire when a variant has no price in the cart's currency. prepareLineItemData handles the now-undefined unitPrice safely, and the integration test is well-scoped and uses in-scope fixtures. One required item: a changeset is missing for the packages/core/core-flows change (the checklist marks it done, but none is present). Minor, non-blocking: unrelated prettier/whitespace reformatting adds scope noise, and the linked issue is referenced without a closing

  • Add a patch changeset for @medusajs/core-flows (yarn changeset); none is present despite the checklist. Message format: fix(core-flows): ...

Triggered by: new PR opened

@medusa-os-bot

medusa-os-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

Thanks for the contribution! A few items need to be addressed before this can move forward:

The core fix is correct: the calculatedPriceSet guard prevents the 500 TypeError and lets the existing INVALID_DATA (400) error fire for variants unpriced in the cart's currency; the integration test is well-scoped and uses in-scope fixtures. One required change: the added changeset marks @medusajs/core-flows as 'major', which (per the changeset-bot) triggers a major version bump across ~80 packages. A bug fix should be a 'patch'. Minor, non-blocking: unrelated prettier/whitespace reformatting (two blank lines added around line 1123 of the test, and the variantIds/isCustomPrice reflow) adds sc

  • .changeset/metal-drinks-pay.md: bump type is 'major'; a bug fix should be 'patch' per CONTRIBUTING — 'major' incorrectly bumps all dependent packages.

Triggered by: new commit pushed

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.

500 TypeError (reading 'calculated_amount') instead of 400 "do not have a price" when adding a variant unpriced in the cart's region

1 participant