From a8794d48de11c4b31f7d8f0dd254caf17daf052e Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Tue, 12 Mar 2024 04:11:33 -0300 Subject: [PATCH] fix(orchestrator): inject only if it has decorator (#6666) --- .changeset/smart-spoons-sniff.md | 5 +++++ packages/orchestration/src/workflow/local-workflow.ts | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/smart-spoons-sniff.md 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