django-oscar / django-oscar-api

RESTful JSON API for django-oscar
Other
369 stars 160 forks source link

Empty attribute values cause an exception #342

Open JulienPalard opened 6 months ago

JulienPalard commented 6 months ago

When creating a product in the sandbox (in current main branch):

$ curl --user mdk:supersecret -XPOST http://localhost:8000/api/admin/products/ -H "Content-Type: application/json" -d '{"product_class": "testtype", "slug": "test", "attributes": [{"code": "text", "value": "1"}]}'

it works, but when I use an empty value, like:

$ curl --user mdk:supersecret -XPOST http://localhost:8000/api/admin/products/ -H "Content-Type: application/json" -d '{"product_class": "testtype", "slug": "test", "attributes": [{"code": "text", "value": ""}]}'

I'm getting a 500 error.

It looks like it's due to the ProductAttributeValueSerializer's update_or_create method doing:

attribute.save_value(product, value)
return product.attribute_values.get(attribute=attribute)

the save may not save empty values (which looks OK to me) so the following get fails.