medusajs / medusa

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

[Bug]: 2.06 Transfering Ownership via Admin UI results in "Unknown Error" #10295

Closed julianengel closed 3 days ago

julianengel commented 3 days ago

Package.json file

{
  "name": "medusa-starter-default",
  "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",
    "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"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "^2.0.6",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "dotenv": "^16.4.5",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "5.9.7",
    "@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",
    "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"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.18.0

Database and its version

Postgres 17.2

Operating system name and version

Ubuntu 22.04

Browser name

Arc/Firefox/Safari

What happended?

When trying to change ownership of an order through the admin UI, it says: Toast - An unknown error occurred

It shows the dialogue correctly, but then it gives an unexpected error. Using the Medusa Admin UI.

Expected behavior

Change of ownership of order.

Actual behavior

Frontend: An unexpected error occurred

Backend:

error:   Value for OrderChangeAction.action is required, 'undefined' found
entity: OrderChangeAction {
  order_id: 'order_01JDBV9BTKYD0AK07PF6RNGB27',
  order: null,
  return_id: null,
  claim_id: null,
  exchange_id: null,
  version: 2,
  order_change: null,
  reference: 'customer',
  reference_id: 'cus_01JD1YKP8B1C5Q98ZH9REQH8ET',
  details: {
    token: 'redacted',
    original_email: 'redacted'
  },
  raw_amount: null,
  internal_note: null,
  applied: false,
  deleted_at: null,
  order_change_id: 'ordch_01JDMEPEK0J49KRYEXHCYJ11PM',
  id: 'ordchact_01JDMEPEKFRMSQMCG30CZ13WBG',
  created_at: 2024-11-26T14:41:06.671Z,
  updated_at: 2024-11-26T14:41:06.671Z
}
{
  message: "Value for OrderChangeAction.action is required, 'undefined' found\n" +
    'entity: OrderChangeAction {\n' +
    "  order_id: 'order_01JDBV9BTKYD0AK07PF6RNGB27',\n" +
    '  order: null,\n' +
    '  return_id: null,\n' +
    '  claim_id: null,\n' +
    '  exchange_id: null,\n' +
    '  version: 2,\n' +
    '  order_change: null,\n' +
    "  reference: 'customer',\n" +
    "  reference_id: 'cus_01JD1YKP8B1C5Q98ZH9REQH8ET',\n" +
    '  details: {\n' +
    "    token: 'redacted',\n" +
    "    original_email: 'redacted'\n" +
    '  },\n' +
    '  raw_amount: null,\n' +
    '  internal_note: null,\n' +
    '  applied: false,\n' +
    '  deleted_at: null,\n' +
    "  order_change_id: 'ordch_01JDMEPEK0J49KRYEXHCYJ11PM',\n" +
    "  id: 'ordchact_01JDMEPEKFRMSQMCG30CZ13WBG',\n" +
    '  created_at: 2024-11-26T14:41:06.671Z,\n' +
    '  updated_at: 2024-11-26T14:41:06.671Z\n' +
    '}',
  name: 'ValidationError',
  stack: "ValidationError: Value for OrderChangeAction.action is required, 'undefined' found\n" +
    'entity: OrderChangeAction {\n' +
    "  order_id: 'order_01JDBV9BTKYD0AK07PF6RNGB27',\n" +
    '  order: null,\n' +
    '  return_id: null,\n' +
    '  claim_id: null,\n' +
    '  exchange_id: null,\n' +
    '  version: 2,\n' +
    '  order_change: null,\n' +
    "  reference: 'customer',\n" +
    "  reference_id: 'cus_01JD1YKP8B1C5Q98ZH9REQH8ET',\n" +
    '  details: {\n' +
    "    token: 'redacted',\n" +
    "    original_email: 'redacted'\n" +
    '  },\n' +
    '  raw_amount: null,\n' +
    '  internal_note: null,\n' +
    '  applied: false,\n' +
    '  deleted_at: null,\n' +
    "  order_change_id: 'ordch_01JDMEPEK0J49KRYEXHCYJ11PM',\n" +
    "  id: 'ordchact_01JDMEPEKFRMSQMCG30CZ13WBG',\n" +
    '  created_at: 2024-11-26T14:41:06.671Z,\n' +
    '  updated_at: 2024-11-26T14:41:06.671Z\n' +
    '}\n' +
    '    at Function.propertyRequired (/root/nutrified-com/node_modules/@mikro-orm/core/errors.js:68:16)\n' +
    '    at EntityValidator.validateRequired (/root/nutrified-com/node_modules/@mikro-orm/core/entity/EntityValidator.js:49:48)\n' +
    '    at ChangeSetPersister.processProperties (/root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:78:28)\n' +
    '    at /root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:25:46\n' +
    '    at Array.forEach (<anonymous>)\n' +
    '    at ChangeSetPersister.executeInserts (/root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:25:20)\n' +
    '    at ChangeSetPersister.runForEachSchema (/root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:69:31)\n' +
    '    at ChangeSetPersister.executeInserts (/root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:22:25)\n' +
    '    at UnitOfWork.commitCreateChangeSets (/root/nutrified-com/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:741:39)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '⮑ sat /root/nutrified-com/node_modules/@medusajs/core-flows/dist/order/workflows/create-order-change-actions.js: [create-order-change-actions -> create-entities-step (invoke)]\n' +
    '⮑ sat /root/nutrified-com/node_modules/@medusajs/core-flows/dist/order/workflows/transfer/request-order-transfer.js: [request-order-transfer-workflow -> create-order-change-actions-as-step (invoke)]',
  entity: OrderChangeAction {
    order_id: 'order_01JDBV9BTKYD0AK07PF6RNGB27',
    order: null,
    return_id: null,
    claim_id: null,
    exchange_id: null,
    version: 2,
    order_change: null,
    reference: 'customer',
    reference_id: 'cus_01JD1YKP8B1C5Q98ZH9REQH8ET',
    details: {
      token: 'redacted',
      original_email: 'redacted'
    },
    raw_amount: null,
    internal_note: null,
    applied: false,
    deleted_at: null,
    order_change_id: 'ordch_01JDMEPEK0J49KRYEXHCYJ11PM',
    id: 'ordchact_01JDMEPEKFRMSQMCG30CZ13WBG',
    created_at: 2024-11-26T14:41:06.671Z,
    updated_at: 2024-11-26T14:41:06.671Z
  }
}
http:    POST /admin/orders/order_01JDBV9BTKYD0AK07PF6RNGB27/transfer ← https://localhost:9000/app/orders/order_01JDBV9BTKYD0AK07PF6RNGB27/transfer (500) - 59.178 ms

Link to reproduction repo

N/A

julianengel commented 3 days ago

This happens in every scenario:

Guest to Customer Customer to Customer Guest (same email) to Cusotomer

fPolic commented 3 days ago

hey @julianengel, cannot reproduce the issue on my end. Can you share what version of Medusa utils package you have installed. Also could you share: cat node_modules/@medusajs/utils/dist/order/order-change-action.js.

julianengel commented 3 days ago

Sure thing.

node_modules/@medusajs/utils/dist/order/order-change-action.js:

var ChangeActionType;
(function (ChangeActionType) {
    ChangeActionType["FULFILL_ITEM"] = "FULFILL_ITEM";
    ChangeActionType["DELIVER_ITEM"] = "DELIVER_ITEM";
    ChangeActionType["CANCEL_ITEM_FULFILLMENT"] = "CANCEL_ITEM_FULFILLMENT";
    ChangeActionType["ITEM_ADD"] = "ITEM_ADD";
    ChangeActionType["ITEM_REMOVE"] = "ITEM_REMOVE";
    ChangeActionType["ITEM_UPDATE"] = "ITEM_UPDATE";
    ChangeActionType["RECEIVE_DAMAGED_RETURN_ITEM"] = "RECEIVE_DAMAGED_RETURN_ITEM";
    ChangeActionType["RECEIVE_RETURN_ITEM"] = "RECEIVE_RETURN_ITEM";
    ChangeActionType["RETURN_ITEM"] = "RETURN_ITEM";
    ChangeActionType["CANCEL_RETURN_ITEM"] = "CANCEL_RETURN_ITEM";
    ChangeActionType["SHIPPING_ADD"] = "SHIPPING_ADD";
    ChangeActionType["SHIPPING_REMOVE"] = "SHIPPING_REMOVE";
    ChangeActionType["SHIP_ITEM"] = "SHIP_ITEM";
    ChangeActionType["WRITE_OFF_ITEM"] = "WRITE_OFF_ITEM";
    ChangeActionType["REINSTATE_ITEM"] = "REINSTATE_ITEM";
})(ChangeActionType || (exports.ChangeActionType = ChangeActionType = {}));
//# sourceMappingURL=order-change-action.js.map

I'm nor sure I have utils installed?

This is all the medusa libs from the package.json

"@medusajs/admin-sdk": "latest",
"@medusajs/cli": "latest",
"@medusajs/framework": "latest",
"@medusajs/medusa": "^2.0.6",
julianengel commented 3 days ago

Installing utils resolved the issue! Thank you :) Not sure how I managed to not have the, installed.

If anyone else stumbles upon this, npm i @medusajs/utils

julianengel commented 3 days ago

Different question @fPolic, what's the expected flow after transferring the order? because nothing changes, and trying to do it again it says there's already has an existing active order change

Do we need to confirm it somehow?

fPolic commented 3 days ago

Utils package was installed but it seems that you had an older version.

it says there's already has an existing active order change

Order Transfer uses Order Change mechanism and there can only be one active change on an order so either the transfer needs to be accepted/declined by a customer or you cancel the transfer request from Admin.

Do we need to confirm it somehow?

Order transfer is a 2 step process. Original owner of the order needs to accept the transfer request. After you created a transfer request via Admin, an event is dispatched which you can use to send an email to the owner with accept and decline links that include a token from the order change details.

This is a feature that was just introduced. We will publish a blog post with more details tomorrow and add documentation on the topic soon.

julianengel commented 3 days ago

Ah, thank you! Makes sense :) Appreciate it!

I saw the function in the Admin UI a while ago but saw that it was redirecting to a 404, so figured it would come later. Much appreciated!

If I could have one favor to ask, in the blog post/documentation, if you could include how you can cancel it from the admin? Because I couldn't find it anywhere in the default admin ui :) (or if we need to make a custom button for it)

Thanks for all your hard work!

fPolic commented 3 days ago

You can see all order change events in the sidebar on the order details page. There is an event in the timeline "Transfer requested" and you have a "cancel" button below.

julianengel commented 3 days ago

@fPolic That is what I thought as well, but it wasn't there.

Screenshot 2024-11-26 at 8 32 32 PM

In the server logs (npx medusa develop), I also only saw a 200 of the post to create the transfer, but no extra logs. Then on subsequent attempts where an error was thrown, it showed the token and related data.

It could be that I'm running something that is outdated (like the utils were), but the 'cancel' button is not showing up.