Skip to content

[Bug]: Impossible to delete metadata fields from variant, if there is more than 1 field #16163

Description

@ufoch

Package.json file

{
  "name": "@dtc/backend",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "start": "medusa start",
    "dev": "medusa db:migrate && medusa develop",
    "lint": "medusa lint",
    "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=false --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.17.2",
    "@medusajs/admin-shared": "2.17.2",
    "@medusajs/caching": "2.17.2",
    "@medusajs/cli": "2.17.2",
    "@medusajs/dashboard": "2.17.2",
    "@medusajs/draft-order": "2.17.2",
    "@medusajs/framework": "2.17.2",
    "@medusajs/medusa": "2.17.2",
    "@medusajs/ui": "4.1.15",
    "@tanstack/react-query": "5.64.2",
    "react-i18next": "13.5.0",
    "react-router-dom": "6.30.3",
    "zod": "4.2.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.17.2",
    "@swc/core": "^1.7.28",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.12.11",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.4.14",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=20"
  },
  "packageManager": "npm@11.15.0"
}

Node.js version

v22.22.3

Database and its version

PostgreSQL 16.14 (Debian 16.14-1.pgdg13+1)

Operating system name and version

Ubuntu 24.04.4 LTS

Browser name

No response

What happended?

It's not possible to delete a variant.metadata property using the empty string method form the docs, if the field to delete is not the last metadata field (i. e. the total metadata field count is greater than 1). Deletion of the last variant.metadata field seems to be handled differently and works.

It works perfectly for product.metadata, customer.metadata and cart.items.metadata (all tested).

I would be very thankful for a fix.

Expected behavior

Deleting a variant.metadata field by assigning an empty string should remove the property as described in the docs (also if there is more than 1 variant.metadata field).

If the field to delete is the last variant.metadata field, the deletion works, so the bug is only reproducible with more than 1 field present.

Actual behavior

The property doesn't get deleted and instead variant.metadata contains the property with the empty string value, i. e. "propertyName": "".

Link to reproduction repo

The bug occurs in any fresh v2.17.2 project; just add two test properties to any variant metadata and try to delete one of them afterwards; the optimistic UI update works, but persistent deletion doesn't

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