Skip to content

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

Make refundSettings field nullable on RefundSettingsUpdate mutation (#18958)

Lukasz Ostrowski49b2f1c47d9c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f223cda08a..b33c6a7e6f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All notable, unreleased changes to this project will be documented in this file.
### Breaking changes
+- Made `refundSettings` field on `RefundSettingsUpdate` mutation nullable to correctly reflect that it can be `null` when errors occur.
- Fix missing denormalization of shipping methods metadata when creating an order.
- Shipping method metadata is now copied to dedicated order fields (`shipping_method_metadata` and `shipping_method_private_metadata`) during checkout-to-order conversion. This ensures that order metadata remains consistent even if the original shipping method is modified or deleted. As a result, updates made to a shipping method's metadata after order creation will no longer be reflected in the order's `shippingMethod.metadata` field.
- Shipping method metadata is now also denormalized during draft order finalization, ensuring consistent behavior across all order creation flows.
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index d1ff25854c..c0c0f5b09a 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -23165,7 +23165,7 @@ Requires one of the following permissions: MANAGE_SETTINGS.
"""
type RefundSettingsUpdate @doc(category: "Shop") {
"""Refund settings."""
- refundSettings: RefundSettings!
+ refundSettings: RefundSettings
refundSettingsErrors: [RefundSettingsUpdateError!]! @deprecated(reason: "Use `errors` field instead.")
errors: [RefundSettingsUpdateError!]!
}
diff --git a/saleor/graphql/shop/mutations/refund_settings_update.py b/saleor/graphql/shop/mutations/refund_settings_update.py
index e226a5f8ee..a068b7948f 100644
--- a/saleor/graphql/shop/mutations/refund_settings_update.py
+++ b/saleor/graphql/shop/mutations/refund_settings_update.py
@@ -26,9 +26,7 @@ class RefundSettingsUpdateInput(BaseInputObjectType):
class RefundSettingsUpdate(BaseMutation):
- refund_settings = graphene.Field(
- RefundSettings, description="Refund settings.", required=True
- )
+ refund_settings = graphene.Field(RefundSettings, description="Refund settings.")
class Arguments:
input = RefundSettingsUpdateInput(
diff --git a/saleor/graphql/shop/tests/mutations/test_refund_settings_update.py b/saleor/graphql/shop/tests/mutations/test_refund_settings_update.py
index d9a06866d9..265e19bd87 100644
--- a/saleor/graphql/shop/tests/mutations/test_refund_settings_update.py
+++ b/saleor/graphql/shop/tests/mutations/test_refund_settings_update.py
@@ -1,6 +1,7 @@
import graphene
from .....page.models import PageType
+from .....site.error_codes import RefundSettingsErrorCode
from ....tests.utils import assert_no_permission, get_graphql_content
REFUND_SETTINGS_UPDATE_MUTATION = """
@@ -158,8 +159,14 @@ def test_refund_settings_update_invalid_id_format(
)
# then
- content = get_graphql_content(response, ignore_errors=True)
- assert "errors" in content
+ content = get_graphql_content(response)
+ data = content["data"]["refundSettingsUpdate"]
+ assert len(data["errors"]) == 1
+ error = data["errors"][0]
+ assert error["code"] == RefundSettingsErrorCode.GRAPHQL_ERROR.name
+ assert error["field"] == "refundReasonReferenceType"
+ assert error["message"] == "Invalid ID: invalid-id-format. Expected: PageType."
+ assert data["refundSettings"] is None
def test_refund_settings_update_nonexistent_page_type(
@@ -179,6 +186,8 @@ def test_refund_settings_update_nonexistent_page_type(
)
# then
+ # The "not_found" error code is not part of RefundSettingsErrorCode enum,
+ # so this results in a top-level GraphQL serialization error.
content = get_graphql_content(response, ignore_errors=True)
assert "errors" in content
@@ -200,8 +209,17 @@ def test_refund_settings_update_wrong_page_type(
)
# then
- content = get_graphql_content(response, ignore_errors=True)
- assert "errors" in content
+ content = get_graphql_content(response)
+ data = content["data"]["refundSettingsUpdate"]
+ assert len(data["errors"]) == 1
+ error = data["errors"][0]
+ assert error["code"] == RefundSettingsErrorCode.GRAPHQL_ERROR.name
+ assert error["field"] == "refundReasonReferenceType"
+ assert (
+ error["message"]
+ == f"Invalid ID: {product_id}. Expected: PageType, received: Product."
+ )
+ assert data["refundSettings"] is None
def test_refund_settings_update_no_permission_staff(staff_api_client, page_type):