{"record":{"id":"2af7734181d99e91","repo":"medusajs/medusa","slug":"line-item-with-id-input-item-id-was-not-found","errorCode":null,"errorMessage":"Line item with id: ${input.item_id} was not found","messagePattern":"Line item with id: (.+?) was not found","errorType":"exception","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/core/core-flows/src/cart/workflows/update-line-item-in-cart.ts","lineNumber":73,"sourceCode":"  customer: CustomerDTO\n  region: RegionDTO\n}\n\ninterface FindLineItemToUpdateStepInput {\n  cart: CartQueryDTO\n  input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData\n}\n\n/**\n * This step finds the line item to update in the cart and collects its variant\n * id. It throws an error if the line item isn't found in the cart.\n */\nexport const findLineItemToUpdateStep = createStep(\n  \"find-line-item-to-update\",\n  async ({ cart, input }: FindLineItemToUpdateStepInput) => {\n    const item = cart.items.find((i) => i.id === input.item_id)\n    if (!item) {\n      throw new MedusaError(\n        MedusaError.Types.NOT_FOUND,\n        `Line item with id: ${input.item_id} was not found`\n      )\n    }\n\n    const variantIds = [item.variant_id].filter(Boolean)\n    return new StepResponse({ item, variantIds })\n  }\n)\n\ninterface PrepareLineItemUpdateStepInput {\n  input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData\n  variants: any\n  item: CartQueryDTO[\"items\"][number]\n}\n\n/**\n * This step builds the update payload for a cart line item, resolving its unit","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/core-flows/src/cart/workflows/update-line-item-in-cart.ts#L55-L91","documentation":"findLineItemToUpdateStep looks up the requested item_id among the cart's current line items; if absent it throws NOT_FOUND. The cart snapshot passed to the workflow and the cart's actual contents are out of sync.","triggerScenarios":"Calling updateLineItemInCart with an item_id that is not in cart.items — the item was already removed, the cart was emptied, or a stale/wrong id was submitted.","commonSituations":"Storefront holding a stale cart in local state after another tab/request removed items; race between remove and update requests; frontend passing the product/variant id instead of the line item id.","solutions":["Refetch the cart (with items) before updating and submit an id from cart.items","Ensure the UI sends the line item id (item.id), not variant_id or product id","Debounce/serialize quantity update requests to avoid racing a concurrent removal","Treat this as recoverable: prompt the user to refresh their cart"],"exampleFix":"// before\nawait updateLineItemInCartWorkflow(container).run({ input: { cart_id, item_id: variantId, update: { quantity: 2 } } })\n\n// after\nconst { data: [cart] } = await query.graph({ entity: 'cart', filters: { id: cart_id }, fields: ['items.id'] })\nconst item = cart.items.find((i) => i.id === item_id)\nif (!item) throw new Error('Item no longer in cart — refresh')\nawait updateLineItemInCartWorkflow(container).run({ input: { cart_id, item_id: item.id, update: { quantity: 2 } } })","handlingStrategy":"validation","validationCode":"const { data: [cart] } = await query.graph({ entity: 'cart', filters: { id: cart_id }, fields: ['items.id'] })\nif (!cart.items.some((i) => i.id === item_id)) {\n  throw new Error('Line item no longer in cart — refetch cart')\n}","typeGuard":"const isInCart = (cart: CartDTO, itemId: string): boolean =>\n  cart.items?.some((i) => i.id === itemId) ?? false","tryCatchPattern":"try {\n  await updateLineItemInCartWorkflow(container).run({ input })\n} catch (e) {\n  if (e instanceof MedusaError && e.type === MedusaError.Types.NOT_FOUND && /Line item/.test(e.message)) {\n    // refetch cart, reconcile local state, retry or inform user\n  }\n}","preventionTips":["Always send line item ids from a freshly fetched cart, not cached state","Serialize cart mutation requests per cart (queue/debounce)","Distinguish item.id from variant_id in your UI state model"],"tags":["cart","line-item","not-found","stale-state"],"backgroundTag":"resource-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}