Repository: saleor/saleor

Issue:
Editing order change it's status to DRAFT 
### Steps to reproduce the problem
1. Create an order
2. Edit i.e. shipping address
3. Order is changed to draft

### What I expected to happen
Order stays in previous status



Discussion:

Resolving patch:
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -154,6 +154,18 @@ class Meta:
         error_type_class = OrderError
         error_type_field = "order_errors"
 
+    @classmethod
+    def clean_input(cls, info, instance, data):
+        draft_order_cleaned_input = super().clean_input(info, instance, data)
+
+        # We must to filter out field added by DraftOrderUpdate
+        editable_fields = ["billing_address", "shipping_address", "user_email"]
+        cleaned_input = {}
+        for key in draft_order_cleaned_input:
+            if key in editable_fields:
+                cleaned_input[key] = draft_order_cleaned_input[key]
+        return cleaned_input
+
     @classmethod
     def save(cls, info, instance, cleaned_input):
         super().save(info, instance, cleaned_input)


Test patch:
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -1238,6 +1238,7 @@ def test_order_update(
     assert order.billing_address.last_name == graphql_address_data["lastName"]
     assert order.user_email == email
     assert order.user is None
+    assert order.status == OrderStatus.UNFULFILLED
 
 
 def test_order_update_anonymous_user_no_user_email(
@@ -1259,7 +1260,6 @@ def test_order_update_anonymous_user_no_user_email(
                     }
                     order {
                         id
-                        status
                     }
                 }
             }
@@ -1271,13 +1271,13 @@ def test_order_update_anonymous_user_no_user_email(
     response = staff_api_client.post_graphql(
         query, variables, permissions=[permission_manage_orders]
     )
-    content = get_graphql_content(response)
+    get_graphql_content(response)
+    order.refresh_from_db()
     order.shipping_address.refresh_from_db()
     order.billing_address.refresh_from_db()
     assert order.shipping_address.first_name != first_name
     assert order.billing_address.last_name != last_name
-    data = content["data"]["orderUpdate"]["order"]
-    assert data["status"] == OrderStatus.DRAFT.upper()
+    assert order.status == OrderStatus.UNFULFILLED
 
 
 def test_order_update_user_email_existing_user(
@@ -1366,6 +1366,9 @@ def test_order_add_note_as_staff_user(
     assert data["event"]["user"]["email"] == staff_user.email
     assert data["event"]["message"] == message
 
+    order.refresh_from_db()
+    assert order.status == OrderStatus.UNFULFILLED
+
     # Ensure the correct order event was created
     event = order.events.get()
     assert event.type == order_events.OrderEvents.NOTE_ADDED
@@ -1772,6 +1775,7 @@ def test_order_update_shipping(
     order.refresh_from_db()
     shipping_total = shipping_method.get_total()
     shipping_price = TaxedMoney(shipping_total, shipping_total)
+    assert order.status == OrderStatus.UNFULFILLED
     assert order.shipping_method == shipping_method
     assert order.shipping_price_net == shipping_price.net
     assert order.shipping_price_gross == shipping_price.gross