diff --git a/.changeset/smart-spoons-sniff.md b/.changeset/smart-spoons-sniff.md new file mode 100644 index 0000000000..0648bd5c95 --- /dev/null +++ b/.changeset/smart-spoons-sniff.md @@ -0,0 +1,5 @@ +--- +"@medusajs/orchestration": patch +--- + +Inject context only if method use decorator @MedusaContext diff --git a/packages/orchestration/src/workflow/local-workflow.ts b/packages/orchestration/src/workflow/local-workflow.ts index 9c929da4ce..d82879985e 100644 --- a/packages/orchestration/src/workflow/local-workflow.ts +++ b/packages/orchestration/src/workflow/local-workflow.ts @@ -4,6 +4,7 @@ import { MedusaContextType, MedusaModuleType, createMedusaContainer, + isDefined, } from "@medusajs/utils" import { asValue } from "awilix" import { @@ -90,11 +91,10 @@ export class LocalWorkflow { } return async (...args) => { - const ctxIndex = - MedusaContext.getIndex(target, prop as string) ?? args.length - 1 + const ctxIndex = MedusaContext.getIndex(target, prop as string) - const hasContext = args[ctxIndex]?.__type === MedusaContextType - if (!hasContext) { + const hasContext = args[ctxIndex!]?.__type === MedusaContextType + if (!hasContext && isDefined(ctxIndex)) { const context = this_.medusaContext if (context?.__type === MedusaContextType) { delete context?.manager