medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.93k stars 2.6k forks source link

[Bug]: Metadata not automatically returned despite the attribute being in the response #10069

Open Betanoir opened 3 days ago

Betanoir commented 3 days ago

Package.json file

{
  "name": "medusa-next",
  "version": "1.0.3",
  "private": true,
  "author": "Kasper Fabricius Kristensen <kasper@medusajs.com> & Victor Gerbrands <victor@medusajs.com> (https://www.medusajs.com)",
  "description": "Next.js Starter to be used with Medusa server",
  "keywords": [
    "medusa-storefront"
  ],
  "scripts": {
    "dev": "next dev -p 8000",
    "build": "next build",
    "start": "next start -p 8000",
    "lint": "next lint",
    "analyze": "ANALYZE=true next build",
    "test-e2e": "playwright test e2e"
  },
  "dependencies": {
    "@headlessui/react": "^2.2.0",
    "@heroicons/react": "^2.1.5",
    "@hookform/error-message": "^2.0.0",
    "@medusajs/js-sdk": "^2.0.4",
    "@medusajs/ui": "^4.0.1",
    "@meilisearch/instant-meilisearch": "^0.7.1",
    "@paypal/paypal-js": "^5.0.6",
    "@paypal/react-paypal-js": "^7.8.1",
    "@stripe/react-stripe-js": "^1.7.2",
    "@stripe/stripe-js": "^1.29.0",
    "algoliasearch": "^4.20.0",
    "axios": "^1.6.7",
    "lodash": "^4.17.21",
    "next": "^14.0.0",
    "pg": "^8.11.3",
    "qs": "^6.12.1",
    "react": "^18.2.0",
    "react-country-flag": "^3.0.2",
    "react-dom": "^18.2.0",
    "react-instantsearch-hooks-web": "^6.29.0",
    "react-intersection-observer": "^9.3.4",
    "server-only": "^0.0.1",
    "tailwind-merge": "^2.5.4",
    "tailwindcss-radix": "^2.8.0",
    "use-debounce": "^10.0.4",
    "webpack": "^5"
  },
  "devDependencies": {
    "@babel/core": "^7.17.5",
    "@medusajs/types": "^2.0.4",
    "@medusajs/ui-preset": "^2.0.4",
    "@playwright/test": "^1.41.1",
    "@types/lodash": "^4.14.195",
    "@types/node": "17.0.21",
    "@types/pg": "^8.11.0",
    "@types/react": "^18.2.42",
    "@types/react-dom": "^18.2.18",
    "@types/react-instantsearch-dom": "^6.12.3",
    "@vercel/style-guide": "^6.0.0",
    "ansi-colors": "^4.1.3",
    "autoprefixer": "^10.4.2",
    "babel-loader": "^8.2.3",
    "eslint": "8.10.0",
    "eslint-config-next": "^15.0.3",
    "postcss": "^8.4.8",
    "prettier": "^3.3.3",
    "prettier-plugin-tailwindcss": "^0.6.8",
    "tailwindcss": "latest",
    "typescript": "^5.3.2"
  },
  "packageManager": "yarn@3.2.3"
}

Node.js version

v21.7.3

Database and its version

PostgreSQL 13

Operating system name and version

Windows 11

Browser name

Chrome

What happended?

With the sdk.store.products.list api route, I had to specify in the fields that I want metadata returned on the product's variants

Expected behavior

I'm not sure if this is done intentionally, but the metadata attribute is always returned when retrieving a product or listing it using the various routes. If it is intentional, the metadata attribute shouldn't be returned. But if it isn't, the value of metadata should be returned.

My opinion is if an admin user is setting metadata, it should be returned by default in any case, but the metadata attribute is always returned when retrieving a product or listing it

Actual behavior

The values weren't returned, despite the attribute being there in the response with the value of null. I had to specify in the fields that I need metadata returned.

Code ref:

sdk.store.product
    .list(
      {
        handle,
        region_id: regionId,
        fields:
          '*variants.calculated_price,+variants.inventory_quantity,*variants.metadata',
      },
      { next: { tags: ['products'] } },
    )
    .then(({ products }) => products[0])

Without *variants.metadata in fields: image

With *variants.metadata in fields: image

Link to reproduction repo

N/A

thetutlage commented 2 days ago

Hello @Betanoir

Just to make sure I understand the issue. You are saying that by default the value of metadata is set to null in the response. However, once you specify the fields *variants.metadata, then only the value is populated?

Betanoir commented 2 days ago

Hey @thetutlage, that is correct

thetutlage commented 2 days ago

Yup, seems like an issue with the variants node.