Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow null as addresses in checkout create mutation
fowczrek334b68bf8bf5
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex ae4981f2d3..0b5f8a6b59 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -205,7 +205,7 @@ class CheckoutCreate(ModelMutation, I18nMixin):@classmethoddef retrieve_shipping_address(cls, user, data: dict) -> Optional[models.Address]:- if "shipping_address" in data:+ if data.get("shipping_address") is not None:return cls.validate_address(data["shipping_address"])if user.is_authenticated:return user.default_shipping_address@@ -213,7 +213,7 @@ class CheckoutCreate(ModelMutation, I18nMixin):@classmethoddef retrieve_billing_address(cls, user, data: dict) -> Optional[models.Address]:- if "billing_address" in data:+ if data.get("billing_address") is not None:return cls.validate_address(data["billing_address"])if user.is_authenticated:return user.default_billing_addressdiff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex b0d152cfbf..975cb5ffc6 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -203,6 +203,38 @@ def test_checkout_create_multiple_warehouse(assert checkout_line.quantity == 4+def test_checkout_create_with_null_as_addresses(api_client, stock):+ """Create checkout object using GraphQL API."""+ variant = stock.product_variant+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ test_email = "[email protected]"+ variables = {+ "checkoutInput": {+ "lines": [{"quantity": 1, "variantId": variant_id}],+ "email": test_email,+ "shippingAddress": None,+ "billingAddress": None,+ }+ }+ assert not Checkout.objects.exists()+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)+ content = get_graphql_content(response)["data"]["checkoutCreate"]++ # Look at the flag to see whether a new checkout was created or not+ assert content["created"] is True++ new_checkout = Checkout.objects.first()+ assert new_checkout is not None+ checkout_data = content["checkout"]+ assert checkout_data["token"] == str(new_checkout.token)+ assert new_checkout.lines.count() == 1+ checkout_line = new_checkout.lines.first()+ assert checkout_line.variant == variant+ assert checkout_line.quantity == 1+ assert new_checkout.shipping_address is None+ assert new_checkout.billing_address is None++@pytest.mark.parametrize("quantity, expected_error_message, error_code",(