Skip to content

fix(core-flows): filter reservations by line item in createOrderFulfillmentWorkflow#16136

Open
andrewgreenh wants to merge 1 commit into
medusajs:developfrom
andrewgreenh:fix/order-fulfillment-reservations-filter
Open

fix(core-flows): filter reservations by line item in createOrderFulfillmentWorkflow#16136
andrewgreenh wants to merge 1 commit into
medusajs:developfrom
andrewgreenh:fix/order-fulfillment-reservations-filter

Conversation

@andrewgreenh

Copy link
Copy Markdown

Fixes #16135

What
Renames the variables key of the get-reservations remote query in createOrderFulfillmentWorkflow from filter to filters, and adds a changeset (patch bump for @medusajs/core-flows).

Why
RemoteQuery.fetchRemoteData only recognizes the arg names filters, context, and the pagination options — any other arg is silently dropped. Because the query passes its line_item_id constraint under filter (singular), the constraint never reaches the module, and since the entry point is queried without ids, take is set to null. Every fulfillment creation therefore executes listReservationItems({}, { take: null }), fetching and hydrating every reservation item in the database and then using only the entries belonging to the fulfilled line items (via buildReservationsMap).

Results are functionally correct, so this went unnoticed, but the cost scales with the total number of reservations. On our production store (~286k reservation items from per-location reservations across 75 stock locations), each fulfillment creation seq-scans the full table and blocks the Node.js event loop for ~50 seconds, during which the API process serves no other requests. Details and evidence in #16135.

How
One-character fix: filterfilters in the useRemoteQueryStep call, so the line_item_id filter is pushed down to the inventory module query.

Testing

  • Verified against production data via a patched @medusajs/core-flows (pnpm patch with this exact change): fulfillment creation drops from ~50s to well under a second, and pg_stat_user_tables shows no further full scans of reservation_item.
  • The fulfillment flow behaves identically otherwise: buildReservationsMap already keyed by line_item_id, so downstream steps (prepareFulfillmentData, prepareInventoryUpdate) receive the same reservations for the fulfilled items as before.

@andrewgreenh
andrewgreenh requested a review from a team as a code owner July 20, 2026 13:59
@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b363785

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

This PR includes changesets to release 79 packages
Name Type
@medusajs/core-flows Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
integration-tests-http Patch
@medusajs/loyalty-plugin Patch
@medusajs/medusa-oas-cli 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/order 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/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/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query 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
@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 20, 2026

Copy link
Copy Markdown

Thanks for the contribution! Initial automated review looks good.

Correct one-line fix renaming the get-reservations remote query variable from 'filter' to 'filters' in createOrderFulfillmentWorkflow, so the line_item_id constraint is actually pushed down instead of loading every reservation item. Verified against the sibling cancel-order-fulfillment workflow, which uses the same filters/line_item_id pattern, and buildReservationsMap keys by line_item_id so downstream behavior is unchanged. PR template is complete, a proper patch changeset is included, and it links open issue #16135.

Triggered by: new PR opened

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]: createOrderFulfillmentWorkflow loads ALL reservations — filter vs filters typo in the get-reservations query

1 participant