{"record":{"id":"1f476835013039ca","repo":"medusajs/medusa","slug":"invalid-data-1f4768","errorCode":"invalid_data","errorMessage":"Method calculatePrices requires currency_code in the pricing context","messagePattern":"Method calculatePrices requires currency_code in the pricing context","errorType":"exception","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/modules/pricing/src/repositories/pricing.ts","lineNumber":84,"sourceCode":"  async calculatePrices(\n    pricingFilters: PricingFilters,\n    pricingContext: PricingContext = { context: {} },\n    sharedContext: Context = {}\n  ): Promise<CalculatedPriceSetDTO[]> {\n    const manager = this.getActiveManager<SqlEntityManager>(sharedContext)\n    const knex = manager.getKnex()\n    const context = { ...(pricingContext.context || {}) }\n\n    // Extract quantity and currency from context\n    const quantity = context.quantity as number | undefined\n    delete context.quantity\n\n    // Currency code is required\n    const currencyCode = context.currency_code as string | undefined\n    delete context.currency_code\n\n    if (!currencyCode) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Method calculatePrices requires currency_code in the pricing context`\n      )\n    }\n\n    // Generate flatten key-value pairs for rule matching\n    const flattenedKeyValuePairs = flattenObjectToKeyValuePairs(context)\n\n    // First filter by value presence\n    let flattenedContext = Object.entries(flattenedKeyValuePairs).filter(\n      ([, value]) => {\n        const isValuePresent = !Array.isArray(value) && isPresent(value)\n        const isArrayPresent = Array.isArray(value) && value.flat(1).length\n\n        return isValuePresent || isArrayPresent\n      }\n    )\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/pricing/src/repositories/pricing.ts#L66-L102","documentation":"calculatePrices in the pricing module requires the pricing context to include a currency_code, because prices are matched per currency. The method deletes and checks context.currency_code first and throws INVALID_DATA when it is absent or empty.","triggerScenarios":"Calling pricingModuleService.calculatePrices({ context: {} }) or a context built from a cart/product request where currency_code was never set (e.g. missing region currency on the cart, or a workflow that forgot to pass it).","commonSituations":"Creating a cart without a region or currency, calling product pricing with an incomplete context object, or upstream code assuming currency_code is optional.","solutions":["Pass currency_code in the context: context: { currency_code: 'usd' }","If pricing a cart, ensure the cart has a region (or explicit currency) before calculating prices","Default the currency from the region/store settings before calling calculatePrices"],"exampleFix":"// before\nawait pricingModuleService.calculatePrices({ ids, context: {} })\n\n// after\nawait pricingModuleService.calculatePrices({\n  ids,\n  context: { currency_code: 'usd' },\n})","handlingStrategy":"validation","validationCode":"function buildPricingContext(c?: { currency_code?: string }) {\n  const currency_code = c?.currency_code ?? 'usd' // or throw early\n  if (!currency_code) throw new Error('currency_code required')\n  return { ...c, currency_code }\n}\nawait pricingService.calculatePrices({ id, context: buildPricingContext(ctx) })","typeGuard":"const hasCurrencyCode = (\n  ctx: unknown\n): ctx is { currency_code: string } =>\n  typeof ctx === 'object' && ctx !== null &&\n  typeof (ctx as any).currency_code === 'string' &&\n  (ctx as any).currency_code.length > 0","tryCatchPattern":"try {\n  await pricingService.calculatePrices({ id, context })\n} catch (e) {\n  if (e instanceof MedusaError && e.type === MedusaError.Types.INVALID_DATA && /currency_code/.test(e.message)) {\n    return computeFallbackPrice() // or return null price\n  }\n  throw e\n}","preventionTips":["Always derive currency_code from the cart's region before pricing","Default to the store's default currency when the customer hasn't chosen one"],"tags":["pricing","validation","currency"],"backgroundTag":"missing-required-context-field","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}