Skip to content

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

Do not create a new instance on update

Adam Janik31cf3e455da6
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 482edee0a7..8ad7e1ddb0 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -30,11 +30,14 @@ SHIPPING_ADDRESS_FIELD = 'default_shipping_address'
class UserInput(graphene.InputObjectType):
- default_billing_address = AddressInput(
- description='Billing address of the customer.')
email = graphene.String(
description='The unique email address of the user.')
note = graphene.String(description='A note about the user.')
+
+
+class CustomerInput(UserInput):
+ default_billing_address = AddressInput(
+ description='Billing address of the customer.')
default_shipping_address = AddressInput(
description='Shipping address of the customer.')
@@ -141,6 +144,27 @@ class CustomerUpdate(CustomerCreate):
exclude = ['password']
model = models.User
+ @classmethod
+ def clean_input(cls, info, instance, input, errors):
+ default_shipping_address = input.pop('default_shipping_address', None)
+ default_billing_address = input.pop('default_billing_address', None)
+ cleaned_input = super().clean_input(info, instance, input, errors)
+
+ if default_shipping_address:
+ instance.default_shipping_address = models.Address(
+ **default_shipping_address)
+ cls.clean_instance(instance.default_shipping_address, errors)
+ cleaned_input[
+ 'default_shipping_address'] = instance.default_shipping_address
+ if default_billing_address:
+ instance.default_billing_address = models.Address(
+ **default_billing_address)
+ cls.clean_instance(instance.default_billing_address, errors)
+ cleaned_input[
+ 'default_billing_address'] = instance.default_billing_address
+
+ return cleaned_input
+
class StaffCreate(ModelMutation):
class Arguments: