internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: saleor/saleor

Issue:
Order draft should be able to reset its shipping method to null
Currently, it is not possible to unpin the shipping method from the draft order. It stands against order draft's "sandbox mode", where user should be able to do anything that does not break any internal logic. `OrderUpdateShipping` mutation returns an error if `null` instead of ID was provided.


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
@@ -161,7 +161,7 @@ def mutate(cls, root, info, id, input):
         order = cls.get_node_or_error(info, id, errors, 'id', Order)
 
         if not input['shipping_method']:
-            if order.is_shipping_required():
+            if not order.is_draft() and order.is_shipping_required():
                 cls.add_error(
                     errors, 'shippingMethod',
                     'Shipping method is required for this order.')


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
@@ -1264,6 +1264,23 @@ def test_order_update_shipping_incorrect_shipping_method(
         'Shipping method cannot be used with this order.')
 
 
+def test_draft_order_clear_shipping_method(
+        staff_api_client, draft_order, permission_manage_orders):
+    assert draft_order.shipping_method
+    query = ORDER_UPDATE_SHIPPING_QUERY
+    order_id = graphene.Node.to_global_id('Order', draft_order.id)
+    variables = {'order': order_id, 'shippingMethod': None}
+    response = staff_api_client.post_graphql(
+        query, variables, permissions=[permission_manage_orders])
+    content = get_graphql_content(response)
+    data = content['data']['orderUpdateShipping']
+    assert data['order']['id'] == order_id
+    draft_order.refresh_from_db()
+    assert draft_order.shipping_method is None
+    assert draft_order.shipping_price == ZERO_TAXED_MONEY
+    assert draft_order.shipping_method_name is None
+
+
 def test_orders_total(
         staff_api_client, permission_manage_orders, order_with_lines):
     query = """
Repository: saleor/saleor

Issue:
Change mutation errors field from [Error] to [Error!]?
Currently `errors` is an optional list of optional errors. While returning an empty list is probably not needed, current type forces the client to make sure the errors themselves are not null.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -44,7 +44,7 @@ class ModelMutationOptions(MutationOptions):
 
 class BaseMutation(graphene.Mutation):
     errors = graphene.List(
-        Error,
+        graphene.NonNull(Error),
         description='List of errors that occurred executing the mutation.')
 
     class Meta:


Test patch:
Repository: saleor/saleor

Issue:
Improve generating example shipping methods
In the `populatedb` script we should change the way how we generate example shipping method. [In this line](https://github.com/mirumee/saleor/blob/master/saleor/core/utils/random_data.py#L441) we generate `minimum_order_price` at random for each shipping method. This may result in a situation where all shipping methods for a particular country have high minimum price, and as a result no shipping method is available at checkout. This is problematic especially in our public demo where people may only single single products just to test the checkout and they're unable to complete it.

We should change the script to always generate at least one shipping method starting from zero price so that there is always at least one method available.


Discussion:

Resolving patch:
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -442,8 +442,8 @@ def create_shipping_zone(
             type=(
                 ShippingMethodType.PRICE_BASED if random.randint(0, 1)
                 else ShippingMethodType.WEIGHT_BASED),
-            minimum_order_price=fake.money(), maximum_order_price=None,
-            minimum_order_weight=fake.weight(), maximum_order_weight=None)
+            minimum_order_price=0, maximum_order_price=None,
+            minimum_order_weight=0, maximum_order_weight=None)
         for name in shipping_methods_names])
     return 'Shipping Zone: %s' % shipping_zone
 


Test patch:
Repository: saleor/saleor

Issue:
Saleor eCommerce, Mirumee Software in pdf
### What I'm trying to achieve
Make pdf with my custom name instead of Saleor eCommerce, Mirumee Software

### Steps to reproduce the problem
make order and fullfill and make pdf
### What I expected to happen
My brand new ecommerce company

### Screenshots
<!-- If applicable, add screenshots to help explain your problem. -->
<img width="1207" alt="schermafbeelding 2018-12-22 om 13 35 35" src="https://user-images.githubusercontent.com/7673074/50374426-8b5d1780-05ee-11e9-81cf-f778935a403b.png">

**System information**
Operating system: 
Browser:



Discussion:

Resolving patch:
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -1,4 +1,5 @@
 from django.conf import settings
+from django.contrib.sites.models import Site
 from django.contrib.sites.shortcuts import get_current_site
 from django.template.loader import get_template
 
@@ -31,14 +32,19 @@ def _create_pdf(rendered_template, absolute_url):
 
 
 def create_invoice_pdf(order, absolute_url):
-    ctx = {'order': order}
+    ctx = {
+        'order': order,
+        'site': Site.objects.get_current()}
     rendered_template = get_template(INVOICE_TEMPLATE).render(ctx)
     pdf_file = _create_pdf(rendered_template, absolute_url)
     return pdf_file, order
 
 
 def create_packing_slip_pdf(order, fulfillment, absolute_url):
-    ctx = {'order': order, 'fulfillment': fulfillment}
+    ctx = {
+        'order': order,
+        'fulfillment': fulfillment,
+        'site': Site.objects.get_current()}
     rendered_template = get_template(PACKING_SLIP_TEMPLATE).render(ctx)
     pdf_file = _create_pdf(rendered_template, absolute_url)
     return pdf_file, order


Test patch:
Repository: saleor/saleor

Issue:
Classic Storefront Changes
**HOMEPAGE**
DESKTOP:
- [x] Search bar - change style
- [x] Change basket icon
- [x] Adjust color pallette
- [x] Change Footer

MOBILE:
- [x] Fix PWA STOREFRONT message - shows under navi bar
- [x] Adjust color pallette
- [x] Change Icons
- [x] Change Footer

**CATEGORY PAGE**
DESKTOP:
- [x] Change Breadcrumbs
- [x] Change style of Filters
- [ ] Add number of products

MOBILE: 
- [ ] Change Filters behaviour
- [ ] Add number of products

**PRODUCT PAGE**
DESKTOP: 
- [x] Change gallery behaviour
- [x] Adjust Colors

MOBILE: 
- [ ] Add gallery indicators
- [x] Adjust Colors

**CHECKOUT**
- [x] Adjust style

Designs are here:
https://www.figma.com/file/DgsfSV7zP0gFlBMyEKu9Itad/NORMAL-SALEOR-STOREFRONT?node-id=0%3A1


Discussion:
Thanks, @pwgryglak. These are the changes that we want to apply to the old Django-based storefront to refresh its appearance a bit before we entirely move on to Storefront 2.0.
I'd opt for a simple change of cards appearance to make them look like the ones in the new storefront.
That should be quite an easy task

Resolving patch:
diff --git a/saleor/core/templatetags/shop.py b/saleor/core/templatetags/shop.py
--- a/saleor/core/templatetags/shop.py
+++ b/saleor/core/templatetags/shop.py
@@ -23,6 +23,12 @@ def menu(site_menu=None, horizontal=False):
         'horizontal': horizontal}
 
 
+@register.inclusion_tag('footer_menu.html')
+def footer_menu(site_menu=None):
+    menu_items = site_menu.json_content if site_menu else []
+    return {'menu_items': menu_items}
+
+
 @register.simple_tag
 def get_menu_item_name(menu_item, lang_code):
     translated = menu_item['translations'].get(lang_code)
diff --git a/saleor/settings.py b/saleor/settings.py
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -608,3 +608,8 @@ def get_host():
     'RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST': True,
     'RELAY_CONNECTION_MAX_LIMIT': 100
 }
+
+CHECKOUT_PAYMENT_GATEWAYS = {
+    DUMMY: pgettext_lazy('Payment method name', 'Dummy gateway'),
+    BRAINTREE: 'Braintree'
+}


Test patch:
Repository: saleor/saleor

Issue:
Server error when filter orders by payment status
### Steps to reproduce the problem
1. Go to django-based dashboard's order list page
2. Select any payment status and click ```Filter```
3. Crash

### Explanation

- This is because ```payment__status``` doesn't exist.


Discussion:

Resolving patch:
diff --git a/saleor/dashboard/order/filters.py b/saleor/dashboard/order/filters.py
--- a/saleor/dashboard/order/filters.py
+++ b/saleor/dashboard/order/filters.py
@@ -45,7 +45,7 @@ class OrderFilter(SortedFilterSet):
         widget=forms.Select)
     payment_status = ChoiceFilter(
         label=pgettext_lazy('Order list filter label', 'Payment status'),
-        field_name='payments__status',
+        field_name='payments__charge_status',
         choices=ChargeStatus.CHOICES,
         empty_label=pgettext_lazy('Filter empty choice label', 'All'),
         widget=forms.Select)


Test patch:
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -1075,3 +1075,10 @@ def test_order_event_display(admin_user, type, order):
     event = OrderEvent(
         user=admin_user, order=order, parameters=parameters, type=type)
     event.get_event_display()
+
+
+def test_filter_order_by_status(admin_client):
+    url = reverse('dashboard:orders',)
+    data = {'status': 'unfulfilled', 'payment_status': 'charged'}
+    response = admin_client.get(url, data)
+    assert response.status_code == 200
Repository: saleor/saleor

Issue:
Successfully paid orders are no longer redirected to the success page
### What I'm trying to achieve
Get the "Thank you for your order!" message after the user successfully paid.

### Steps to reproduce the problem
1. Make an order;
2. Pay it;
3. It doesn't redirect to `payment_success` anymore.

### What I expected to happen
To get redirected to the `payment_success`.

### References (dead codes):
https://github.com/mirumee/saleor/blob/56b5bce1a127d531d3eb0bfb1daba2f383aed0d7/saleor/order/urls.py#L14-L17

https://github.com/mirumee/saleor/blob/56b5bce1a127d531d3eb0bfb1daba2f383aed0d7/saleor/order/views.py#L151-L157

---

How should we handle the payment success? Should we always say "Thanks for your payment!", or should we redirect the user back to the order?

----
*Issue created from https://github.com/mirumee/saleor/issues/3250#issuecomment-442130475.*


Discussion:
I don't have a strong preference actually but personaly I would recommend saying thank you and add a link to view the order. This is an explicit way to indicate the users that the payment is successful. Redireting users back to the order directly sounds a little bit confusing for the users about the status of the order.
This must be a bug after recent changes in payments. We should definitely fix this.

Resolving patch:
diff --git a/saleor/order/views.py b/saleor/order/views.py
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -123,6 +123,8 @@ def start_payment(request, order, gateway):
             except Exception as exc:
                 form.add_error(None, str(exc))
             else:
+                if order.is_fully_paid():
+                    return redirect('order:payment-success', token=order.token)
                 return redirect(order.get_absolute_url())
 
     ctx = {


Test patch:
diff --git a/tests/test_order.py b/tests/test_order.py
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -469,7 +469,7 @@ def test_order_payment_flow(
 
     assert response.status_code == 302
     redirect_url = reverse(
-        'order:details', kwargs={'token': order.token})
+        'order:payment-success', kwargs={'token': order.token})
     assert get_redirect_location(response) == redirect_url
 
     # Assert that payment object was created and contains correct data
Repository: saleor/saleor

Issue:
Add query to fetch order by token
Add query to fetch order by token:
`orderByToken(token: String!): Order`

This query should allow to fetch the order without checking any additional permissions. This will be used in Storefront 2.0 to render order details page e.g. by anonymous users who don't have any account, but have received an order confirmation link.

Existing `order(id: ID)` should stay - it will be used by Dashboard 2.0.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.py
--- a/saleor/graphql/order/resolvers.py
+++ b/saleor/graphql/order/resolvers.py
@@ -59,3 +59,7 @@ def resolve_homepage_events(info):
         OrderEvents.PLACED.value, OrderEvents.PLACED_FROM_DRAFT.value,
         OrderEvents.ORDER_FULLY_PAID.value]
     return models.OrderEvent.objects.filter(type__in=types)
+
+
+def resolve_order_by_token(info, token):
+    return models.Order.objects.filter(token=token).first()
diff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.py
--- a/saleor/graphql/order/schema.py
+++ b/saleor/graphql/order/schema.py
@@ -18,8 +18,8 @@
     OrderAddNote, OrderCancel, OrderCapture, OrderMarkAsPaid, OrderRefund,
     OrderUpdate, OrderUpdateShipping, OrderVoid)
 from .resolvers import (
-    resolve_homepage_events, resolve_order, resolve_orders,
-    resolve_orders_total)
+    resolve_homepage_events, resolve_order, resolve_order_by_token,
+    resolve_orders, resolve_orders_total)
 from .types import Order, OrderEvent
 
 
@@ -44,6 +44,9 @@ class OrderQueries(graphene.ObjectType):
         period=graphene.Argument(
             ReportingPeriod,
             description='Get total sales for selected span of time.'))
+    order_by_token = graphene.Field(
+        Order, description='Lookup an order by token.',
+        token=graphene.Argument(graphene.String, required=True))
 
     @permission_required('order.manage_orders')
     def resolve_homepage_events(self, info, **kwargs):
@@ -62,6 +65,9 @@ def resolve_orders(
     def resolve_orders_total(self, info, period, **kwargs):
         return resolve_orders_total(info, period)
 
+    def resolve_order_by_token(self, info, token):
+        return resolve_order_by_token(info, token)
+
 
 class OrderMutations(graphene.ObjectType):
     draft_order_complete = DraftOrderComplete.Field()


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
@@ -1316,3 +1316,19 @@ def test_orders_total(
     assert (
         content['data']['ordersTotal']['gross']['amount'] ==
         order_with_lines.total.gross.amount)
+
+
+def test_order_by_token_query(api_client, order):
+    query = """
+    query OrderByToken($token: String!) {
+        orderByToken(token: $token) {
+            id
+        }
+    }
+    """
+    order_id = graphene.Node.to_global_id('Order', order.id)
+
+    response = api_client.post_graphql(query, {'token': order.token})
+    content = get_graphql_content(response)
+
+    assert content['data']['orderByToken']['id'] == order_id
Repository: saleor/saleor

Issue:
Broken logo in docs
### Steps to reproduce the problem
1. https://saleor.readthedocs.io/en/latest/gettingstarted.html
2. 
![Screenshot 2019-04-03 at 20 28 48](https://user-images.githubusercontent.com/5188636/55503534-23878580-564f-11e9-9399-5fed22b1ad20.png)

**System information**
Operating system: OSX
Browser: Chrome



Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -129,7 +129,7 @@
 
 # The name of an image file (relative to this directory) to place at the top
 # of the sidebar.
-html_logo = 'logo-white.svg'
+html_logo = 'logo.svg'
 
 # The name of an image file (within the static path) to use as favicon of the
 # docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32


Test patch:
Repository: saleor/saleor

Issue:
High number of duplicated queries on home page
### What I'm trying to achieve
Trying out Saleor

### Steps to reproduce the problem
1. Install Saleor
2. Use the populatedb management command
3. Access homepage `http://localhost:8000/en/`

### What I expected to happen
No duplicated queries, or at least less of them.

### Screenshots

<img width="706" alt="Screen Shot 2019-04-02 at 15 01 46" src="https://user-images.githubusercontent.com/12426/55408618-4aaf5b80-5558-11e9-857f-c752af99340b.png">


**System information**
Operating system: MacOS
Browser: Chrome



Discussion:
Thanks for reporting. We'll investigate the issue.
That wasn't cute. Good catch!
<img width="185" alt="Screenshot 2019-04-11 at 16 11 03" src="https://user-images.githubusercontent.com/6186720/55964118-6ca19000-5c74-11e9-862a-6624240b4d24.png">
<img width="185" alt="Screenshot 2019-04-11 at 16 10 53" src="https://user-images.githubusercontent.com/6186720/55964117-6ca19000-5c74-11e9-88aa-69544608bd84.png">


Resolving patch:
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -41,7 +41,8 @@ def products_for_products_list(user):
 def products_for_homepage(user, homepage_collection):
     products = products_visible_to_user(user)
     products = products.prefetch_related(
-        'translations', 'images', 'variants__variant_images__image')
+        'translations', 'images', 'variants__variant_images__image',
+        'collections')
     products = products.filter(collections=homepage_collection)
     return products
 
diff --git a/saleor/product/views.py b/saleor/product/views.py
--- a/saleor/product/views.py
+++ b/saleor/product/views.py
@@ -151,8 +151,10 @@ def category_index(request, slug, category_id):
             category_id=category_id)
     # Check for subcategories
     categories = category.get_descendants(include_self=True)
-    products = products_for_products_list(user=request.user).filter(
-        category__in=categories).order_by('name')
+    products = products_for_products_list(user=request.user)\
+        .filter(category__in=categories)\
+        .order_by('name')\
+        .prefetch_related('collections')
     product_filter = ProductCategoryFilter(
         request.GET, queryset=products, category=category)
     ctx = get_product_list_context(request, product_filter)


Test patch:
Repository: saleor/saleor

Issue:
Catch all exceptions when decoding JWT token in TokenVerify mutation
Currently, `TokenVerify` mutation returns an error if the token is malformed or is created with the different secret key. Instead, it should always return `null` if the token is not valid.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -496,3 +496,10 @@ def resolve_user(self, _info, **_kwargs):
         username_field = get_user_model().USERNAME_FIELD
         kwargs = {username_field: self.payload.get(username_field)}
         return models.User.objects.get(**kwargs)
+
+    @classmethod
+    def mutate(cls, root, info, token, **kwargs):
+        try:
+            return super().mutate(root, info, token, **kwargs)
+        except JSONWebTokenError:
+            return None


Test patch:
diff --git a/tests/api/test_core.py b/tests/api/test_core.py
--- a/tests/api/test_core.py
+++ b/tests/api/test_core.py
@@ -4,6 +4,7 @@
 import pytest
 from django.core.exceptions import ImproperlyConfigured
 from django.utils import timezone
+from graphql_jwt.shortcuts import get_token
 
 from saleor.graphql.core.enums import ReportingPeriod
 from saleor.graphql.core.mutations import BaseMutation
@@ -219,3 +220,34 @@ def _run_test():
             ImproperlyConfigured,
             message='Permissions should be a tuple or a string in Meta'):
         _run_test()
+
+
+MUTATION_TOKEN_VERIFY = """
+    mutation tokenVerify($token: String!){
+        tokenVerify(token: $token){
+            user{
+                email
+            }
+        }
+    }
+"""
+
+
+def test_verify_token(api_client, customer_user):
+    variables = {
+        "token": get_token(customer_user)
+    }
+    response = api_client.post_graphql(MUTATION_TOKEN_VERIFY, variables)
+    content = get_graphql_content(response)
+    user_email = content['data']['tokenVerify']['user']['email']
+    assert customer_user.email == user_email
+
+
+def test_verify_token_incorrect_token(api_client):
+    variables = {
+        "token": "incorrect_token"
+    }
+    response = api_client.post_graphql(MUTATION_TOKEN_VERIFY, variables)
+    content = get_graphql_content(response)
+    assert not content['data']['tokenVerify']
+
Repository: saleor/saleor

Issue:
Duplicate choices in shipping address
### What I'm trying to achieve
I'm trying to set shipping user for Russian user and there are duplicate values in "Oblast" selector.

### Steps to reproduce the problem
1. Create new shipping address
2. Country --> Russia
3. There are duplicated values in "Oblast" selector

### What I expected to happen
There are no duplicated values in "Oblast" selector

### Screenshots
What happens now
<img src="https://user-images.githubusercontent.com/13136992/53255369-8a239600-36d6-11e9-84a6-24a10b96a321.png" width="300">


What I expect to see
<img src="https://user-images.githubusercontent.com/13136992/53255400-99a2df00-36d6-11e9-8913-ecaec174487a.png" width="300">


**System information**
Operating system: Manjaro Linux
Browser: Google Chrome 72.0.3626.81



Discussion:
By the way, it has same issue for the GraphQL API. The API returns duplicated item with same ```raw``` but different ```verbose```

Resolving patch:
diff --git a/saleor/account/forms.py b/saleor/account/forms.py
--- a/saleor/account/forms.py
+++ b/saleor/account/forms.py
@@ -46,6 +46,11 @@ def get_address_form(
             not preview and data or None,
             initial=initial_address,
             **kwargs)
+
+    if hasattr(address_form.fields['country_area'], 'choices'):
+        choices = address_form.fields['country_area'].choices
+        choices = [(choice[1], choice[1]) for choice in choices]
+        address_form.fields['country_area'].choices = choices
     return address_form, preview
 
 


Test patch: