medusa icon indicating copy to clipboard operation
medusa copied to clipboard

cannot create product without profile_id via the product service

Open richardwardza opened this issue 2 years ago • 2 comments

Bug report

Describe the bug

When trying to create a product using the ProductService.create method and not specifying a profile_id (it's optional) then the creation fails with the message: failed: null value in column "profile_id" violates not-null constraint

The API POST /products is different, it first retrieves a shipping profile and uses that id in the creation of the product

The other issue is this is not picked up in any of the tests as they use mocks of services and there are no "end to end" service tests.

System information

Medusa version (including plugins): 1.3.5 Node.js version: v16.15.1 Database: postgres Operating system: mac Browser (if relevant):

Steps to reproduce the behavior

run this "somewhere" - a plugin loader/index is an easy place.

const productService: ProductService = container.resolve("productService");
await productService.create({ title: "a product" });
// fails with: failed: null value in column "profile_id" violates not-null constraint

Expected behavior

I would think that it would be best to update the service to retrieve the profile_id (similar to the API endpoint) if it is not supplied.

Updating the profile_id to be mandatory would be a breaking change to that interface and would require anyone else using it to update their code.

Code snippets

const productService: ProductService = container.resolve("productService");
await productService.create({ title: "a product" });
// fails with: failed: null value in column "profile_id" violates not-null constraint

Additional context

nothing

richardwardza avatar Aug 11 '22 08:08 richardwardza

I'm happy to do some work on this if needed..

richardwardza avatar Aug 11 '22 08:08 richardwardza

Doing the shippingProfile lookup in the service is not the correct way to go so re-doing this by making the profile_id mandatory and seeing where that takes me.

richardwardza avatar Aug 16 '22 07:08 richardwardza