fix(fulfillment): respect cancellation guard overrides - #16745
fix(fulfillment): respect cancellation guard overrides#16745kudala-bharani wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 05eab92 The changes in this PR will be included in the next version bump. This PR includes changesets to release 83 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. This PR fixes a real bug in FulfillmentModuleService.cancelFulfillment: the cancellation guard (canCancelFulfillmentOrThrow) was always called via the hardcoded FulfillmentModuleService class reference, so any subclass override was silently bypassed. The fix replaces the hardcoded reference with this.constructor as typeof FulfillmentModuleService, which is the standard JavaScript pattern for polymorphic dispatch on a static method. The PR is well-scoped: - Linked to a valid, open issue (#16744, labelled good first issue / type: bug). - PR template is fully filled out (What/Why/How/Testing sections). - Patch changeset included with the correct fix(fulfillment): … format and @medusajs/fulfillment: patch bump type. - Five focused unit tests cover: default shipped/delivered rejections (unchanged default behaviour), subclass override permitting each state, and a subclass enforcing a custom restriction. - No security, performance, or correctness concerns. Minor non-blocking note: the local variable Service in fulfillment-module-service.ts uses PascalCase. Medusa's conventions require local variables to be camelCase; a name like ServiceClass would be more conventional. This does not affect correctness. Triggered by: new PR opened |
Summary
What — Make
cancelFulfillmentrespect a subclass'scanCancelFulfillmentOrThrowoverride.Why — The hardcoded
FulfillmentModuleServicereference always invokes the base guard, even when a custom module overrides it. Fixes #16744.How — Resolve the guard through the service's runtime constructor. The base class still rejects shipped and delivered fulfillments; no default cancellation rules change. Includes a patch changeset.
Testing
yarn workspace @medusajs/fulfillment test --runInBand).yarn workspace @medusajs/fulfillment buildpasses. The dependency build also passed for all 13 required packages.Examples
A custom fulfillment module overriding
canCancelFulfillmentOrThrowcan now enforce its own cancellation policy without reimplementingcancelFulfillmentand its provider, persistence, and event-handling logic.Checklist