medusajs/medusa · error · MedusaError
Variants ${variantNotFoundOrPublished.join( ", "
Error message
Variants ${variantNotFoundOrPublished.join(
", "
)} do not exist or belong to a product that is not published What it means
getVariantsAndItemsWithPricesWorkflow validates every requested variant id against fetched, published products. Ids that resolve to nothing — deleted/nonexistent variants or variants of unpublished products — are collected and reported in one aggregate invalid_data error.
Source
Thrown at packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts:164
isCustomPrice: isCustomPrice,
}
if (variant && !isCustomPrice && calculatedPriceSet) {
input.unitPrice = calculatedPriceSet.calculated_amount
input.isTaxInclusive =
calculatedPriceSet.is_calculated_price_tax_inclusive
}
const preparedItem = prepareLineItemData(input)
return {
selector: { id: (item_ as CartLineItemDTO).id },
data: preparedItem as Partial<UpdateLineItemDTO>,
}
})
if (variantNotFoundOrPublished.length > 0) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Variants ${variantNotFoundOrPublished.join(
", "
)} do not exist or belong to a product that is not published`
)
}
if (priceNotFound.length > 0) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Variants with IDs ${priceNotFound.join(", ")} do not have a price`
)
}
const result: GetVariantsAndItemsWithPricesWorkflowOutput = {
variants: variantsData,
lineItems: items,
}
return new StepResponse(result)View on GitHub (pinned to 5e06e544a2)
Solutions
- Verify the variant exists and its product status is 'published' before adding it to a cart
- Publish the product via Admin (POST /admin/products/:id/publish) if it should be sellable
- Invalidate storefront caches when products/variants change
- Handle 404s from catalog endpoints so stale ids never reach the cart
Example fix
// before
await addToCartWorkflow(container).run({ input: { cart_id, items: [{ variant_id, quantity: 1 }] } })
// after
const { data } = await query.graph({ entity: 'variant', fields: ['id', 'product.status'], filters: { id: variant_id } })
if (!data[0] || data[0].product.status !== 'published') throw new Error('Variant unavailable')
await addToCartWorkflow(container).run({ input: { cart_id, items: [{ variant_id, quantity: 1 }] } }) Defensive patterns
Strategy: validation
Validate before calling
const { data } = await query.graph({ entity: 'variant', fields: ['id', 'product.status'], filters: { id: variantIds } })
const bad = variantIds.filter((id) => {
const v = data.find((x) => x.id === id)
return !v || v.product.status !== 'published'
})
if (bad.length) throw new Error(`Unavailable variants: ${bad.join(', ')}`) Type guard
const isSellableVariant = (v?: VariantDTO): v is VariantDTO => !!v && v.product?.status === 'published'
Try / catch
try {
await addToCartWorkflow(container).run({ input })
} catch (e) {
if (e instanceof MedusaError && /not published|do not exist/.test(e.message)) {
// remove unavailable ids from client state, show 'no longer available'
}
} Prevention
- Invalidate product caches on publish/unpublish/delete events
- Storefront adds should use ids from the live catalog response
- Handle catalog 404s so stale ids never reach addToCart
When it happens
Trigger: Calling addToCartWorkflow / updateCart with variant ids that don't exist, whose products have status != 'published', or that were soft-deleted; also stale ids cached in the client.
Common situations: Storefront caching product/variant data past unpublish or deletion; drafts mistakenly exposed to the storefront; re-using seed data ids after a DB reset; products unpublished during a sale window while carts remain active.
Related errors
- invalid_data
- Variants with IDs ${priceNotFound.join(", ")} do not have a
- invalid_data
- No regions found
- Cart ${cart.id} already has a payment collection
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/c792661efc9f9017.
Report an issue: GitHub.