Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Provide default Sale.type when missing (#15291)

Maciej Korycinskia55b5ededd71
diff --git a/saleor/graphql/discount/tests/queries/test_sale.py b/saleor/graphql/discount/tests/queries/test_sale.py
index eb90b9b317..4c6cbac5c5 100644
--- a/saleor/graphql/discount/tests/queries/test_sale.py
+++ b/saleor/graphql/discount/tests/queries/test_sale.py
@@ -1,5 +1,7 @@
import graphene
+from saleor.discount import DiscountValueType
+
from ....tests.utils import (
assert_no_permission,
get_graphql_content,
@@ -188,3 +190,30 @@ def test_staff_query_sale_no_channel_provided(
assert sale_data["type"] == rule.reward_value_type.upper()
assert not sale_data["discountValue"]
assert not sale_data["currency"]
+
+
+def test_query_sale_when_type_is_not_provided(
+ staff_api_client,
+ promotion_converted_from_sale,
+ permission_manage_discounts,
+ channel_USD,
+):
+ # given
+ promotion = promotion_converted_from_sale
+ rule = promotion.rules.first()
+ rule.reward_value_type = None
+ rule.save()
+ variables = {
+ "id": graphene.Node.to_global_id("Sale", promotion.old_sale_id),
+ "channel": channel_USD.slug,
+ }
+
+ # when
+ response = staff_api_client.post_graphql(
+ QUERY_SALE_BY_ID, variables, permissions=[permission_manage_discounts]
+ )
+
+ # then
+ content = get_graphql_content(response)
+ sale_data = content["data"]["sale"]
+ assert sale_data["type"] == DiscountValueType.FIXED.upper()
diff --git a/saleor/graphql/discount/types/sales.py b/saleor/graphql/discount/types/sales.py
index e137e5a33d..59f3f14237 100644
--- a/saleor/graphql/discount/types/sales.py
+++ b/saleor/graphql/discount/types/sales.py
@@ -1,7 +1,7 @@
import graphene
from graphene import relay
-from ....discount import models
+from ....discount import DiscountValueType, models
from ....permission.enums import DiscountPermissions
from ....product.models import Category, Collection, Product, ProductVariant
from ...channel import ChannelQsContext
@@ -141,7 +141,7 @@ class Sale(ChannelContextTypeWithMetadata, ModelObjectType[models.Promotion]):
def resolve_type(root: ChannelContext[models.Promotion], info: ResolveInfo):
def _get_type(rules):
# We ensure, that old sales have at least one rule associated.
- return rules[0].reward_value_type
+ return rules[0].reward_value_type or DiscountValueType.FIXED
return (
PromotionRulesByPromotionIdLoader(info.context)