Skip to content

[Bug]: Cannot retrieve inventory_quantity for cart line item variants via fields param #12884

@leosin

Description

@leosin

Package.json file

{
  "name": "sysbom",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "engines": {
    "node": ">=20"
  },
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "setup": "./scripts/setup.sh",
    "deploy": "./scripts/deploy.sh",
    "deploy:prod": "NODE_ENV=production ./scripts/deploy.sh",
    "pm2:start": "pm2 start ecosystem.config.js",
    "pm2:stop": "pm2 stop medusa-app",
    "pm2:restart": "pm2 restart medusa-app",
    "pm2:logs": "pm2 logs medusa-app",
    "check": "yarn tsc --noEmit && yarn test:unit && yarn build"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.8.6",
    "@medusajs/cli": "2.8.6",
    "@medusajs/framework": "2.8.6",
    "@medusajs/medusa": "2.8.6",
    "@mikro-orm/core": "6.4.3",
    "@mikro-orm/knex": "6.4.3",
    "@mikro-orm/migrations": "6.4.3",
    "@mikro-orm/postgresql": "6.4.3",
    "awilix": "8.0.1",
    "pg": "8.13.0"
  },
  "devDependencies": {
    "@antfu/eslint-config": "4.16.1",
    "@medusajs/test-utils": "2.8.6",
    "@mikro-orm/cli": "6.4.3",
    "@swc/core": "1.5.7",
    "@swc/jest": "0.2.36",
    "@types/jest": "29.5.13",
    "@types/node": "20.0.0",
    "@types/react": "18.3.2",
    "@types/react-dom": "18.2.25",
    "eslint": "9.29.0",
    "jest": "29.7.0",
    "prop-types": "15.8.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "ts-node": "10.9.2",
    "typescript": "5.6.2",
    "vite": "5.2.11",
    "yalc": "1.0.0-pre.53"
  }
}

Node.js version

v22.14.0

Database and its version

PostgreSQL 17

Operating system name and version

macOS Sequoia 15.5

Browser name

chrome

What happended?

Describe the bug
When requesting a cart via /store/carts/:id and using the fields query parameter to include variant details, it is not possible to retrieve the inventory_quantity field for each line item's variant.

  • Using +*items.variant returns the variant object, but does NOT include inventory_quantity.
  • Trying +items.variant.inventory_quantity or +variants.inventory_quantity in the fields param results in a 500 server error.

Thank you for your help!

Expected behavior

  • The API should allow requesting inventory_quantity for each line item's variant via the fields parameter, as documented.
  • No server error should occur when requesting this field.

Actual behavior

To Reproduce

  1. Add a product with a variant to the cart.
  2. Request the cart with:
    GET /store/carts/{cart_id}?fields=+*items.variant,+items.variant.inventory_quantity
    
  3. Observe that:
    • The response includes the variant object, but without inventory_quantity.
    • If you try to add +items.variant.inventory_quantity or +variants.inventory_quantity, the server returns a 500 error.

Link to reproduction repo

GET /store/carts/{cart_id}?fields=+*items.variant,+items.variant.inventory_quantity

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions