Skip to content

Inventory quantity is missing after upgrading / cannot activate inventory module on products that are created before the upgrade #3793

Description

@habibullahturkmen

Bug report

Describe the bug

Products created prior to Medusa 1.8

The product already has 10 items in the inventory. When I activate "manage inventory" button on the new admin panel. I get the following error:
POST http://localhost:9000/admin/inventory-items 500 (Internal Server Error)
Response: {"code":"unknown_error","type":"unknown_error","message":"An unknown error occurred."}

System information

Medusa version (including plugins): 1.8
"@medusajs/admin": "^2.0.0",
"@medusajs/cache-redis": "^1.8.0",
"@medusajs/event-bus-redis": "^1.8.0",
"@medusajs/inventory": "^1.8.0",
"@medusajs/medusa": "^1.8.0",
"@medusajs/medusa-cli": "^1.3.8",
"@medusajs/stock-location": "^1.8.0",
"express": "^4.18.2",
"medusa-file-minio": "^1.1.6",
"medusa-fulfillment-manual": "^1.1.37",
"medusa-interfaces": "^1.3.7",
"medusa-payment-manual": "^1.0.23",
"medusa-payment-stripe": "^2.0.0",
"medusa-plugin-meilisearch": "^2.0.0",
"medusa-plugin-sendgrid": "^1.3.8",
"medusa-plugin-slack-notification": "^1.3.9",
"nodemailer": "^6.9.1",
"nodemailer-mailgun-transport": "^2.1.5",
"typeorm": "0.3.11"

Node.js version: v18.15.0
Database: PostgreSQL 15
Operating system: Windows 11
Browser (if relevant): Google Chrome / Mozilla Firefox

Steps to reproduce the behavior

  1. Medusa version should be below 1.8. Go to the legacy admin panel.
  2. Create a new product with a single variant and 10 items in the inventory and save. (name: dummy shirt)
  3. Upgrade Medusa to v1.8, and add the new admin panel plugin.
  4. Go through the Upgrade Guide step by step (every single step) https://github.com/medusajs/medusa/releases/v1.8.0
  5. fire up the server
  6. go to the new admin panel (v2.0.0)
  7. edit the (dummy shirt) product (click edit on the products section)
  8. go to the variants section and click manage inventory on the variants section.
  9. model pops up (Edit stock & inventory)
  10. on the inventory section: toggle manage inventory (here we cannot see the 10 items that we created before the upgrade)
  11. click the manage locations button and add a location
  12. add stock, e.g. 10 items
  13. then click save and close
  14. we get the error: POST http://localhost:9000/admin/inventory-items 500 (Internal Server Error)

Expected behavior

  1. After upgrading to 1.8, we should be able to see the in-stock items that we added before upgrading to 1.8.
  2. Manage inventory should work for products that are created before the upgrade (v1.8)

Screenshots

This product was created before the upgrade (v1.8)
image

Code snippets

If applicable, add code samples to help explain your problem

Additional context: logs

image
info: Processing inventory-item.created which has 0 subscribers
error: Cannot read properties of undefined (reading 'inventory_item_id')
TypeError: Cannot read properties of undefined (reading 'inventory_item_id')
at C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:187:95
at step (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:57:23)
at Object.next (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:38:53)
at fulfilled (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:29:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
::1 - - [10/Apr/2023:19:39:41 +0000] "POST /admin/inventory-items HTTP/1.1" 500 86 "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
info: Processing inventory-item.created which has 0 subscribers
::1 - - [10/Apr/2023:19:40:57 +0000] "GET /admin/batch-jobs?limit=100 HTTP/1.1" 304 - "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
::1 - - [10/Apr/2023:19:42:41 +0000] "GET /admin/batch-jobs?limit=100 HTTP/1.1" 304 - "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
::1 - - [10/Apr/2023:19:43:42 +0000] "GET /admin/batch-jobs?limit=100 HTTP/1.1" 304 - "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
::1 - - [10/Apr/2023:19:45:13 +0000] "GET /admin/batch-jobs?limit=100 HTTP/1.1" 304 - "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
::1 - - [10/Apr/2023:19:47:46 +0000] "GET /admin/batch-jobs?limit=100 HTTP/1.1" 304 - "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
error: Cannot read properties of undefined (reading 'inventory_item_id')
TypeError: Cannot read properties of undefined (reading 'inventory_item_id')
at C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:187:95
at step (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:57:23)
at Object.next (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:38:53)
at fulfilled (C:\Users\Habibullah\Projects\medusa\medusa-production\medusa-api\node_modules@medusajs\medusa\dist\api\routes\admin\inventory-items\create-inventory-item.js:29:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
::1 - - [10/Apr/2023:19:49:03 +0000] "POST /admin/inventory-items HTTP/1.1" 500 86 "http://localhost:9000/app/a/products/prod_01GVJYRM9ZZDBKMJBFP77JTR2J" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
info: Processing inventory-item.created which has 0 subscribers
error: Cannot read properties of undefined (reading 'inventory_item_id')

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions