Open Stouffi opened 6 months ago
Thanks for highlighting this. Would you be up for sending a PR with a fix?
I've tried to dig deeper and find out that a few other parts of the code may omit to check for null variant.
I've made some changes on a fork based on a change in the type of LineItem Entity to add | null
for variant relation as it was already the case for variant_id
. This single change helped me to spot every piece of code affected by unchecked nulls.
I'll submit a PR soon today or tomorrow. I added comments where I'm not sure about the expected behavior handling custom line items so that we can discuss it in reviews
Bug report
Describe the bug
When a draft order contains a custom line item (i.e. a line item not related to any variant), this will make the endpoint GET /store/carts/[id-of-the-draft-order-cart] crash if an inventory service is registered in the modules of the project configuration.
System information
Medusa version (including plugins): 1.20.2
Node.js version: 20.11.1 Database: PostgreSQL 12 Operating system: 5.15.133.1-microsoft-standard-WSL2 Browser (if relevant):
Steps to reproduce the behavior
The following error is printed in the backend logs
Expected behavior
No errors and the cart data being returned by the api.
Additional context
This code from https://github.com/medusajs/medusa/blob/develop/packages/medusa/src/services/product-variant-inventory.ts#L832 is causing the bug.