Skip to content

Commit 56a7896

Browse files
authored
Fix: resolve 500 error when creating product with null attribute value (#374)
1 parent c9a930b commit 56a7896

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

oscarapi/serializers/product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def to_internal_value(self, data):
276276

277277
def get_value(self, dictionary):
278278
values = super(ProductAttributeValueListSerializer, self).get_value(dictionary)
279-
if values is empty:
279+
if not values or values is empty:
280280
return values
281281

282282
product_class, parent = getitems(dictionary, "product_class", "parent")

oscarapi/tests/unit/testproduct.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,13 @@ def test_put_product_ambiguous(self):
17501750
)
17511751
self.response.assertStatusEqual(404)
17521752

1753+
def test_post_product_with_null_attributes(self):
1754+
"Test creating a product with null attributes should return a 400 Bad Request"
1755+
self.login("admin", "admin")
1756+
data = {"product_class": "testtype", "slug": "test", "attributes": None}
1757+
self.response = self.post("admin-product-list", **data)
1758+
self.response.assertStatusEqual(400)
1759+
17531760
def test_put_child(self):
17541761
self.login("admin", "admin")
17551762
url = reverse("admin-product-detail", args=(2,))

0 commit comments

Comments
 (0)