Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fixed crash of sale form when required values are missing
NyanKiyoshie1d8460e0f9a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 79ab829988..ca381e90b7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -79,6 +79,7 @@ All notable, unreleased changes to this project will be documented in this file.- Add support for webhooks - #4731 by @korycins- Fixed the random failure of `populatedb` trying to create a new user with an existing email - #4769 by @NyanKiyoshi- Fixed the inability of filtering attributes using `inCategory` and `inCollection` and deprecated those fields to use `filter { inCollection: ..., inCategory: ... }` instead - #4700 by @NyanKiyoshi & @khalibloo+- Fixed internal error when updating or creating a sale with missing required values - #4778 by @NyanKiyoshi## 2.8.0diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex c037dfa8cb..c6a40a3940 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -59,6 +59,9 @@ class SaleForm(forms.ModelForm):def clean(self):cleaned_data = super().clean()+ if self.errors:+ return cleaned_data+discount_type = cleaned_data["type"]value = cleaned_data["value"]if discount_type == DiscountValueType.PERCENTAGE and value > 100:diff --git a/tests/dashboard/test_discounts.py b/tests/dashboard/test_discounts.pyindex 4f20753060..aced6e531b 100644--- a/tests/dashboard/test_discounts.py+++ b/tests/dashboard/test_discounts.py@@ -74,6 +74,25 @@ def test_view_sale_add(admin_client, category, collection):assert collection in sale.collections.all()+def test_view_sale_update_invalid_values(admin_client, sale, collection):+ url = reverse("dashboard:sale-update", kwargs={"pk": sale.pk})+ data = {+ "name": sale.name,+ "categories": [],+ "collections": [],+ "start_date": "2018-01-01",+ }++ response = admin_client.post(url, data)+ assert response.status_code == 200++ form_ctx = response.context["form"]+ assert form_ctx.errors == {+ "type": ["This field is required."],+ "value": ["This field is required."],+ }++def test_view_sale_add_requires_product_category_or_collection(admin_client, category, product, collection):