Skip to content

fix: medusa-service generated update functions always returns an array even if single object is passed. - #12880

Closed
dwene wants to merge 10 commits into
medusajs:developfrom
lambda-curry:fix/medusa-service-update-always-returns-array
Closed

fix: medusa-service generated update functions always returns an array even if single object is passed.#12880
dwene wants to merge 10 commits into
medusajs:developfrom
lambda-curry:fix/medusa-service-update-always-returns-array

Conversation

@dwene

@dwene dwene commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

Related to the change with Medusa Internal Service here: https://github.com/medusajs/medusa/pull/12715/files#diff-4d287d33cf799750dfc3957d3c22d87a5d369ca15bbbc7db29265fc864cedfadL248

Context: all of my medusa-service generated update functions are always returning an array, forcing me to have to check the response myself.

ex:

export const updateThemeStep = createStep(
  'update-theme-step',
  async (input: UpdateCheckoutThemeWorkflowStepInput, { container }) => {
    const themeModuleService: ThemeModuleService = container.resolve(CHECKOUT_THEME_MODULE);

    const { channel_id, ...updateThemeData } = input;

    const originalTheme = await queryCheckoutTheme({ container, themeId: input.id });

    const theme = await themeModuleService.updateCheckoutThemes(updateThemeData);

    if (Array.isArray(theme)) return new StepResponse(theme[0], originalTheme);

    return new StepResponse(theme, originalTheme);
  },
  async (originalTheme, { container }) => {
    if (!originalTheme) return;

    const themeModuleService: ThemeModuleService = container.resolve(CHECKOUT_THEME_MODULE);

    await themeModuleService.updateCheckoutThemes(originalTheme);
  }
);

@dwene
dwene requested a review from a team as a code owner July 2, 2025 20:02
@changeset-bot

changeset-bot Bot commented Jul 2, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 571414f

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

This PR includes changesets to release 69 packages
Name Type
@medusajs/utils Patch
@medusajs/framework Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis 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/region Patch
@medusajs/sales-channel Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google 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/oas-github-ci Patch
@medusajs/js-sdk Patch
@medusajs/types 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

@vercel

vercel Bot commented Jul 2, 2025

Copy link
Copy Markdown

@dwene is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread packages/core/utils/src/modules-sdk/medusa-service.ts Outdated
dwene and others added 4 commits July 12, 2025 15:08
- Add tests for single object input/output consistency
- Add tests for array input/output consistency
- Add proper mocks for create/update service methods
- Fix update method to preserve input type (single object vs array)
- Tests validate the bug fix where update method was always returning arrays
…ub.com:lambda-curry/medusa into fix/medusa-service-update-always-returns-array
@dwene

dwene commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

@olivermrbl OK all the tests are passing now. Looks like create had the same issue.

@dwene
dwene requested a review from a team as a code owner August 5, 2025 18:52
@dwene

dwene commented Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

Looks like this was fixed by a core team member in PR #13225 so I'm going to close this.

Thanks for fixing this @carlos-r-l-rodrigues !

@dwene dwene closed this Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants