Skip to content

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

Fix error in case of not provided orderSetting (#11961)

Krzysztof Waliczek46bc74cb8f23
diff --git a/saleor/graphql/channel/mutations/channel_create.py b/saleor/graphql/channel/mutations/channel_create.py
index 50bc4d71a9..c7c8a733e6 100644
--- a/saleor/graphql/channel/mutations/channel_create.py
+++ b/saleor/graphql/channel/mutations/channel_create.py
@@ -130,6 +130,7 @@ class ChannelCreate(ModelMutation):
cleaned_input[
"automatically_fulfill_non_shippable_gift_card"
] = automatically_fulfill_non_shippable_gift_card
+
return cleaned_input
@classmethod
diff --git a/saleor/graphql/channel/mutations/channel_update.py b/saleor/graphql/channel/mutations/channel_update.py
index 7f23749e91..093290ce18 100644
--- a/saleor/graphql/channel/mutations/channel_update.py
+++ b/saleor/graphql/channel/mutations/channel_update.py
@@ -91,12 +91,20 @@ class ChannelUpdate(ModelMutation):
if stock_settings := cleaned_input.get("stock_settings"):
cleaned_input["allocation_strategy"] = stock_settings["allocation_strategy"]
if order_settings := cleaned_input.get("order_settings"):
- cleaned_input["automatically_confirm_all_new_orders"] = order_settings[
+ automatically_confirm_all_new_orders = order_settings.get(
"automatically_confirm_all_new_orders"
- ]
- cleaned_input[
+ )
+ if automatically_confirm_all_new_orders is not None:
+ cleaned_input[
+ "automatically_confirm_all_new_orders"
+ ] = automatically_confirm_all_new_orders
+ automatically_fulfill_non_shippable_gift_card = order_settings.get(
"automatically_fulfill_non_shippable_gift_card"
- ] = order_settings["automatically_fulfill_non_shippable_gift_card"]
+ )
+ if automatically_fulfill_non_shippable_gift_card is not None:
+ cleaned_input[
+ "automatically_fulfill_non_shippable_gift_card"
+ ] = automatically_fulfill_non_shippable_gift_card
return cleaned_input
diff --git a/saleor/graphql/channel/tests/mutations/test_channel_update.py b/saleor/graphql/channel/tests/mutations/test_channel_update.py
index 320ad606eb..28119d7ead 100644
--- a/saleor/graphql/channel/tests/mutations/test_channel_update.py
+++ b/saleor/graphql/channel/tests/mutations/test_channel_update.py
@@ -752,6 +752,39 @@ def test_channel_update_order_settings_manage_orders(
)
+def test_channel_update_order_settings_empty_order_settings(
+ permission_manage_orders,
+ staff_api_client,
+ channel_USD,
+):
+ # given
+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
+ variables = {
+ "id": channel_id,
+ "input": {
+ "orderSettings": {},
+ },
+ }
+
+ # when
+ response = staff_api_client.post_graphql(
+ CHANNEL_UPDATE_MUTATION,
+ variables=variables,
+ permissions=(permission_manage_orders,),
+ )
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["channelUpdate"]
+ assert not data["errors"]
+ channel_data = data["channel"]
+ assert channel_data["orderSettings"]["automaticallyConfirmAllNewOrders"] is True
+ assert (
+ channel_data["orderSettings"]["automaticallyFulfillNonShippableGiftCard"]
+ is True
+ )
+
+
def test_channel_update_order_settings_manage_orders_as_app(
permission_manage_orders,
app_api_client,