Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot update product_option_value with productService.updateProductOptionValues #10293

Open
opeah opened this issue Nov 26, 2024 · 1 comment · May be fixed by #10883
Open

[Bug]: Cannot update product_option_value with productService.updateProductOptionValues #10293

opeah opened this issue Nov 26, 2024 · 1 comment · May be fixed by #10883
Assignees

Comments

@opeah
Copy link

opeah commented Nov 26, 2024

Package.json file

{
  "version": "1.0.0",
  "scripts": {
    "build": "npx medusa build",
    "dev": "npx medusa develop",
    "start": "npx medusa start"
  },
  "dependencies": {
    "@lexical/html": "^0.18.0",
    "@lexical/list": "^0.18.0",
    "@lexical/react": "^0.18.0",
    "@lexical/utils": "^0.18.0",
    "@medusajs/admin-sdk": "2.0.6",
    "@medusajs/framework": "2.0.6",
    "@medusajs/icons": "2.0.6",
    "@medusajs/medusa": "2.0.6",
    "@medusajs/medusa-cli": "rc",
    "@medusajs/ui": "4.0.1",
    "@radix-ui/react-popover": "1.1.2",
    "@react-input/mask": "1.2.11",
    "@tanstack/react-query": "catalog:",
    "@tanstack/react-query-devtools": "5.59.14",
    "@types/color": "4.2.0",
    "@types/lodash": "4.17.10",
    "attr-accept": "2.2.2",
    "class-variance-authority": "0.7.0",
    "clsx": "catalog:",
    "color": "4.2.3",
    "lexical": "0.20.0",
    "lodash": "4.17.21",
    "lucide-react": "0.446.0",
    "react": "catalog:react18",
    "react-colorful": "5.6.1",
    "react-dom": "catalog:react18",
    "react-dropzone": "14.2.9",
    "react-hook-form": "catalog:",
    "react-router-dom": "6.20.1",
    "slugify": "1.6.6",
    "zod": "catalog:"
  },
  "devDependencies": {
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "0.2.36",
    "@types/jest": "29.5.12",
    "@types/node": "catalog:",
    "@types/react": "catalog:react18",
    "@types/react-dom": "catalog:react18",
    "jest": "29.7.0",
    "medusa-test-utils": "rc",
    "ts-node": "10.9.2",
    "typescript": "catalog:",
    "vite": "5.2.11"
  }
}

Node.js version

v23.2.0

Database and its version

postgres@14

Operating system name and version

macOS 13.6.6

Browser name

Arc

What happended?

Cannot update product_option_value with method productService.updateProductOptionValues

export async function PATCH(
  req: MedusaRequest<UpdateProductOptionValueDTO>,
  res: MedusaResponse,
) {
  const { option_value_id: optionValueId } = req.params;
  if (!optionValueId) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      'Missing params Option Value ID',
    );
  }
  const productService = req.scope.resolve(Modules.PRODUCT);
  const productOptionValue = await productService.updateProductOptionValues(
    optionValueId,
    { metadata: { rank: 0 } },
  );
  return res.json({ productOptionValue });
}

Expected behavior

product_option_value should be updated

Actual behavior

I receive an error

error:   ProductOptionValue with id "" not found
MedusaError: ProductOptionValue with id "" not found
    at AbstractService_.update (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/medusa-internal-service.ts:339:17)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async transaction.transaction (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/decorators/inject-transaction-manager.ts:63:18)
    at async fork.getConnection.transactional (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@mikro-orm+core_3hccqwwc7tgosgawyrq2dxxzfu/node_modules/@mikro-orm/core/EntityManager.js:774:29)
    at async PostgreSqlConnection.transactional (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@mikro-orm/knex/AbstractSqlConnection.js:36:25)
    at async transactionWrapper (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/dal/utils.ts:32:10)
    at async MikroOrmAbstractBaseRepository_.transaction (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/dal/mikro-orm/mikro-orm-repository.ts:72:12)
    at async AbstractService_.descriptor.value (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/decorators/inject-transaction-manager.ts:32:14)
    at async ProductModuleService.methodImplementation (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/medusa-service.ts:217:26)
    at async ProductModuleService.descriptor.value (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/decorators/inject-into-context.ts:27:14)
    at async ProductModuleService.descriptor.value (/Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/modules-sdk/decorators/emit-events.ts:26:22)
    at async PATCH (/Users/sebastiencrepin/Data/Projects/nexa/packages/medusa/app/src/api/admin/products/[id]/options/[option_id]/values/[option_value_id]/route.ts:19:30)
    at async /Users/sebastiencrepin/Data/Projects/nexa/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@mikr_fcggamrs7etmugeq6ppbgpmcy4/node_modules/@medusajs/utils/src/common/wrap-handler.ts:17:14 {
  __isMedusaError: true,
  type: 'not_found',
  code: undefined,
  date: 2024-11-26T13:07:49.577Z
}

I double checked, ID is correct: optval_01JAJG35ZQH3AFVDBV83JS91CY

Link to reproduction repo

https://github.com/medusajs/medusa-starter-default

@jaykanjia
Copy link

try this

const productOptionValue = await productService.updateProductOptionValues(
{
id: optionValueId,
metadata: { rank: 0 }
},
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants