{"record":{"id":"d8343a9b9bea6eef","repo":"medusajs/medusa","slug":"region-with-id-req-filterablefields-region-id-n-d8343a","errorCode":null,"errorMessage":"Region with id ${req.filterableFields.region_id} not found when populating the tax context","messagePattern":"Region with id (.+?) not found when populating the tax context","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/medusa/src/api/utils/middlewares/products/set-tax-context.ts","lineNumber":58,"sourceCode":"        taxInclusivityContext: inclusivity,\n      }\n      return next()\n    } catch (e) {\n      next(e)\n    }\n  }\n}\n\nconst getTaxInclusivityInfo = async (req: MedusaRequest) => {\n  const region = await refetchEntity({\n    entity: \"region\",\n    idOrFilter: req.filterableFields.region_id as string,\n    scope: req.scope,\n    fields: [\"automatic_taxes\"],\n  })\n\n  if (!region) {\n    throw new MedusaError(\n      MedusaError.Types.INVALID_DATA,\n      `Region with id ${req.filterableFields.region_id} not found when populating the tax context`\n    )\n  }\n\n  return {\n    automaticTaxes: region.automatic_taxes,\n  }\n}\n\nconst getTaxLinesContext = async (req: MedusaRequest) => {\n  if (!req.filterableFields.country_code) {\n    return\n  }\n\n  const taxContext = {\n    address: {\n      country_code: req.filterableFields.country_code as string,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/medusa/src/api/utils/middlewares/products/set-tax-context.ts#L40-L76","documentation":"Thrown by getTaxInclusivityInfo in set-tax-context when req.filterableFields.region_id references a region that does not exist. The middleware needs the region's automatic_taxes setting to decide tax-inclusive pricing behavior, so an unknown region aborts the request.","triggerScenarios":"GET /store/products?region_id=<nonexistent-or-deleted id> on an endpoint that runs setTaxContext (store product routes). Same stale/typo'd region ids as the pricing variant of this error.","commonSituations":"Region deleted and recreated with a new id while clients still send the old one; multi-environment id mixing; typo in a manually constructed URL.","solutions":["Fetch current regions with GET /store/regions and use one of those ids","Invalidate cached region ids in the client whenever regions change","Omit region_id and let the store default region apply"],"exampleFix":"// before\nGET /store/products?region_id=reg_deleted\n\n// after\nGET /store/products?region_id=reg_valid","handlingStrategy":"validation","validationCode":"// validate region before any request that builds tax context\nconst { regions } = await sdk.store.region.list()\nconst valid = regions.some((r) => r.id === requestedRegionId)\nif (!valid) requestedRegionId = regions[0]?.id","typeGuard":"const isKnownRegion = (id: string | undefined, known: string[]): id is string =>\n  !!id && known.includes(id)","tryCatchPattern":"try {\n  await sdk.store.product.list({ region_id: id })\n} catch (e) {\n  if (e.type === 'invalid_data' && /tax context/.test(e.message)) {\n    // drop the stale region and refetch with a valid/default one\n  }\n  throw e\n}","preventionTips":["Treat region ids as volatile; resolve them from /store/regions at runtime","Add monitoring for 400s containing 'region' to catch stale-id drift early"],"tags":["region","tax-context","store-api","not-found"],"backgroundTag":"invalid-region-id","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}