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

Issue:
Cannot place order in saleor demo's storefront
### What I'm trying to achieve
Place an order on the demo store to reproduce another bug. :wink:

### Steps to reproduce the problem
1. Create a cart with an item;
2. Follow the checkout until the summary page;
3. Try to hit "Order & Pay";
4. A server error should occur.

**System information**
```
Host: demo.getsaleor.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept-Language: en,en-GB;q=0.8,en-US
Accept-Encoding: gzip, deflate, br
Referer: https://demo.getsaleor.com/en/checkout/summary/
```


Discussion:
It has been fixed now.
It's back.
There is a problem with address anonymization. The error being thrown is:

```
MultipleObjectsReturned
get() returned more than one Address -- it returned 2!
```

and it happens in `store_user_address` function in this line:
```
address, _ = user.addresses.get_or_create(**address.as_data())
```

Apparently, multiple similar addresses in the database became the same after anonymization. Therefore Django cannot distinguish between them. For now, I've cleared and recreated the database. Quick fix around that would be to use `filter` instead of `get`.
Looks like the address is being duplicated during the address creation as when deleting the duplicate one from account details, the checkout doesn't crash anymore.

I will take a look if I have 5 minutes later today.

Resolving patch:
diff --git a/saleor/account/utils.py b/saleor/account/utils.py
--- a/saleor/account/utils.py
+++ b/saleor/account/utils.py
@@ -4,11 +4,11 @@
 
 def store_user_address(user, address, address_type):
     """Add address to user address book and set as default one."""
-    address, _ = user.addresses.get_or_create(**address.as_data())
-
     # DEMO: obfuscate user address
     address = obfuscate_address(address)
 
+    address, _ = user.addresses.get_or_create(**address.as_data())
+
     if address_type == AddressType.BILLING:
         if not user.default_billing_address:
             user.default_billing_address = address


Test patch:
Repository: saleor/saleor

Issue:
populatedb can generate products with less than zero gross margin
It just looks really weird if product has -132% gross margin. We should check while generating data if cost price is always less than sale price. Otherwise we end up with products like the one below:

<img width="402" alt="zrzut ekranu 2018-04-13 o 11 00 13" src="https://user-images.githubusercontent.com/6833443/38726243-e5df7f88-3f09-11e8-96bf-662c91770e28.png">


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
@@ -2,6 +2,7 @@
 import os
 import random
 import unicodedata
+from decimal import Decimal
 
 from django.conf import settings
 from django.contrib.auth.models import Group, Permission
@@ -301,10 +302,12 @@ def create_variant(product, **kwargs):
     defaults = {
         'product': product,
         'quantity': fake.random_int(1, 50),
-        'cost_price': fake.money(),
         'quantity_allocated': fake.random_int(1, 50)}
     defaults.update(kwargs)
     variant = ProductVariant(**defaults)
+    if 'cost_price' not in kwargs:
+        variant.cost_price = (variant.base_price * Decimal(
+            fake.random_int(10, 99) / 100)).quantize()
     if variant.attributes:
         variant.name = get_name_from_attributes(variant)
     variant.save()


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4,6 +4,7 @@
 
 import pytest
 from django.conf import settings
+from django.db.models import Case, F, When
 from django.shortcuts import reverse
 from django.urls import translate_url
 from prices import Money
@@ -16,7 +17,7 @@
 from saleor.core.utils.text import get_cleaner, strip_html
 from saleor.discount.models import Sale, Voucher
 from saleor.order.models import Order
-from saleor.product.models import Product, ProductImage
+from saleor.product.models import Product, ProductImage, ProductVariant
 from saleor.shipping.models import ShippingMethod
 
 type_schema = {
@@ -145,6 +146,11 @@ def test_create_products_by_type(
         how_many=how_many, create_images=True)
     assert Product.objects.all().count() == how_many
     assert mock_create_thumbnails.called
+    assert ProductVariant.objects.annotate(
+        base_price=Case(
+            When(price_override__lt=0, then='price_override'),
+            default='product__price')).\
+        filter(base_price__lt=F('cost_price')).count() == 0
 
 
 def test_create_fake_order(db, monkeypatch, product_image):
Repository: saleor/saleor

Issue:
Customize GraphiQL on demo
There are a few things that we want to change in our public GraphiQL explorer to make it more user-friendly:
- provide a welcome text (e.g. https://graphql.github.io/swapi-graphql/)
- provide an example query e.g.
  ```
  {
    shop {
      name
    }
  }
  ```
- set the HTML `title`
- favicon


Discussion:

Resolving patch:
diff --git a/saleor/graphql/file_upload/views.py b/saleor/graphql/file_upload/views.py
--- a/saleor/graphql/file_upload/views.py
+++ b/saleor/graphql/file_upload/views.py
@@ -1,13 +1,48 @@
-from graphene_django.views import GraphQLView
 import json
 import graphene
+from django.shortcuts import render
+from graphene_django.views import GraphQLView
+
+from ...product.models import Product
+
 
 # This class is modified verion of the `ModifiedGraphQLView` class from
 # `graphene-file-upload` (https://github.com/lmcgartland/graphene-file-upload).
 
 
+DEFAULT_QUERY = '''# Welcome to Saleor GraphQL API!
+#
+# This explorer lets you browse data from the demo store using
+# GraphQL queries.
+#
+# Type queries into this side of the screen, and you will see
+# intelligent typeaheads aware of the current GraphQL type schema
+# and live syntax and validation errors highlighted within the text.
+#
+# An example query to fetch a product might look like:
+#
+
+{
+  product(id: "%(product_id)s") {
+    name
+    price {
+      amount
+      currency
+    }
+  }
+}
+'''
+
+
 class FileUploadGraphQLView(GraphQLView):
 
+    def render_graphiql(self, request, **data):
+        if not data['query']:
+            product = Product.objects.order_by('?').first()
+            product_id = graphene.relay.node.to_global_id('Product', product.pk)
+            data['query'] = DEFAULT_QUERY % {'product_id': product_id}
+        return render(request, self.graphiql_template, data)
+
     @staticmethod
     def get_graphql_params(request, data):
         content_type = GraphQLView.get_content_type(request)


Test patch:
Repository: saleor/saleor

Issue:
Countries in address form are not sorted alphabetically due to translation
List of countries in the AddresForm used during checkout is not sorted alphabetically due to translation. As a result, when language is set to different than English, sorting doesn't change.

Below is a screenshot showing that in polish translation Czarnogóra (eng. *Montenegro*)  appears after Mongolia.

![checkout-list](https://user-images.githubusercontent.com/20802901/40622260-ed949ffa-62a0-11e8-9baa-69c507a1bf27.png)



Discussion:
Good catch 👍 
can anyone help me to install this on my domain ? please 

Resolving patch:
diff --git a/saleor/account/i18n.py b/saleor/account/i18n.py
--- a/saleor/account/i18n.py
+++ b/saleor/account/i18n.py
@@ -122,6 +122,10 @@ class Meta:
     def __init__(self, *args, **kwargs):
         autocomplete_type = kwargs.pop('autocomplete_type', None)
         super().__init__(*args, **kwargs)
+        # countries order was taken as defined in the model,
+        # not being sorted accordingly to the selected language
+        self.fields['country'].choices = sorted(
+            COUNTRY_CHOICES, key=lambda choice: choice[1])
         autocomplete_dict = defaultdict(
             lambda: 'off', self.AUTOCOMPLETE_MAPPING)
         for field_name, field in self.fields.items():


Test patch:
Repository: saleor/saleor

Issue:
[cosmetics] dashboard/templatetags/utils.py used __future__
need to remove deprecated unused module

`from __future__ import unicode_literals`


Discussion:

Resolving patch:
diff --git a/saleor/dashboard/templatetags/utils.py b/saleor/dashboard/templatetags/utils.py
--- a/saleor/dashboard/templatetags/utils.py
+++ b/saleor/dashboard/templatetags/utils.py
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
 from json import dumps
 from urllib.parse import urlencode
 


Test patch:
Repository: saleor/saleor

Issue:
Assigning an unpublished collection as a homepage collection
It is possible to assign the unpublished collection as a homepage collection and display it publicly.

### Steps to reproduce the problem
1. Create a collection of products but don't publish it.
2. Go to the collection list view and in the "Homepage collection" card choose the unpublished collection. Submit the form.
3. Go to the storefront's homepage. The featured products section at the bottom shows the unpublished collection.

### What I expected to happen
A validation error in the "Hompage collection" could be raised when trying to assign an unpublished collection.



Discussion:

Resolving patch:
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.py
--- a/saleor/dashboard/collection/forms.py
+++ b/saleor/dashboard/collection/forms.py
@@ -45,3 +45,8 @@ class AssignHomepageCollectionForm(forms.ModelForm):
     class Meta:
         model = SiteSettings
         fields = ('homepage_collection',)
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.fields['homepage_collection'].queryset = \
+            Collection.objects.filter(is_published=True)
diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.py
--- a/saleor/dashboard/collection/views.py
+++ b/saleor/dashboard/collection/views.py
@@ -67,7 +67,12 @@ def collection_update(request, pk=None):
         msg = pgettext_lazy('Collection message', 'Updated collection')
         messages.success(request, msg)
         return redirect('dashboard:collection-update', pk=collection.pk)
-    ctx = {'collection': collection, 'form': form}
+    is_unpublish_restricted = (
+        collection == request.site.settings.homepage_collection and
+        collection.is_published)
+    ctx = {
+        'collection': collection, 'form': form,
+        'is_unpublish_restricted': is_unpublish_restricted}
     return TemplateResponse(request, 'dashboard/collection/detail.html', ctx)
 
 


Test patch:
diff --git a/tests/dashboard/test_collection.py b/tests/dashboard/test_collection.py
--- a/tests/dashboard/test_collection.py
+++ b/tests/dashboard/test_collection.py
@@ -25,6 +25,18 @@ def test_set_homepage_collection(admin_client, collection, site_settings):
     assert site_settings.homepage_collection == collection
 
 
+def test_set_unpublished_homepage_collection(
+        admin_client, collection, site_settings):
+    collection.is_published = False
+    collection.save()
+    data = {'homepage_collection': collection.pk}
+    response = admin_client.post(reverse('dashboard:collection-list'), data)
+    assert response.status_code == 200
+    site_settings.refresh_from_db()
+    assert site_settings.homepage_collection is None
+    assert not response.context['assign_homepage_col_form'].is_valid()
+
+
 def test_collection_form_name():
     data = {'name': 'Test Collection', 'products': []}
     form = CollectionForm(data)
Repository: saleor/saleor

Issue:
Implement product types section in dashboard
Blocked by #2679 


Discussion:

Resolving patch:
diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py
--- a/saleor/core/__init__.py
+++ b/saleor/core/__init__.py
@@ -26,7 +26,7 @@ def check_session_caching(app_configs, **kwargs):  # pragma: no cover
 class TaxRateType:
     ACCOMODATION = 'accomodation'
     ADMISSION_TO_CULTURAL_EVENTS = 'admission to cultural events'
-    ADMISSION_TO_ENTERAINMENT_EVENTS = 'admission to entertainment events'
+    ADMISSION_TO_ENTERTAINMENT_EVENTS = 'admission to entertainment events'
     ADMISSION_TO_SPORTING_EVENTS = 'admission to sporting events'
     ADVERTISING = 'advertising'
     AGRICULTURAL_SUPPLIES = 'agricultural supplies'
@@ -54,7 +54,7 @@ class TaxRateType:
         (ACCOMODATION, pgettext_lazy('VAT rate type', 'accommodation')),
         (ADMISSION_TO_CULTURAL_EVENTS, pgettext_lazy(
             'VAT rate type', 'admission to cultural events')),
-        (ADMISSION_TO_ENTERAINMENT_EVENTS, pgettext_lazy(
+        (ADMISSION_TO_ENTERTAINMENT_EVENTS, pgettext_lazy(
             'VAT rate type', 'admission to entertainment events')),
         (ADMISSION_TO_SPORTING_EVENTS, pgettext_lazy(
             'VAT rate type', 'admission to sporting events')),


Test patch:
diff --git a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
--- a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
+++ b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
@@ -16308,7 +16308,7 @@ exports[`Storyshots Views / Configuration default 1`] = `
       class="Component-root-id"
     >
       <div
-        class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id Component-cardDisabled-id"
+        class="MuiPaper-root-id MuiPaper-elevation1-id MuiPaper-rounded-id MuiCard-root-id Component-card-id"
       >
         <div
           class="MuiCardContent-root-id Component-cardContent-id"
@@ -25491,12 +25491,12 @@ exports[`Storyshots Views / Product types / Product type details default 1`] = `
                       role="button"
                       tabindex="0"
                     >
-                      standard
+                      Accomodation
                     </div>
                     <input
                       name="taxRate"
                       type="hidden"
-                      value="standard"
+                      value="ACCOMODATION"
                     />
                     <svg
                       aria-hidden="true"
Repository: saleor/saleor

Issue:
Remove side effects from Dockerfile
Currently `Dockerfile` performs `./manage.py collectstatic` during the image build process. It's a good idea, but the build behaves differently when AWS credentials are set - it pushes static files automatically to S3.

Docker image build process should always behave in the same way. So I recommend extracting the S3 push process from Docker build process and move it to an external script. It will also make easier to switch object storage provider from AWS to GCP for example.


Discussion:

Resolving patch:
diff --git a/saleor/settings.py b/saleor/settings.py
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -114,10 +114,10 @@ def get_bool_from_env(name, default_value):
 ORDER_FROM_EMAIL = os.getenv('ORDER_FROM_EMAIL', DEFAULT_FROM_EMAIL)
 
 MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
-MEDIA_URL = '/media/'
+MEDIA_URL = os.environ.get('MEDIA_URL', '/media/')
 
 STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
-STATIC_URL = '/static/'
+STATIC_URL = os.environ.get('STATIC_URL', '/static/')
 STATICFILES_DIRS = [
     ('assets', os.path.join(PROJECT_ROOT, 'saleor', 'static', 'assets')),
     ('favicons', os.path.join(PROJECT_ROOT, 'saleor', 'static', 'favicons')),


Test patch:
Repository: saleor/saleor

Issue:
Add shop's default country to API
API should be able to return shop's default country code. Without it, API's user does not know, for example, which tax rates he should fetch.


Discussion:
~Blocks #2665~
Why would tax rate classes depend on the current country?
Okay, it doesn't. Bad example. 

Resolving patch:
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -50,6 +50,8 @@ class Shop(graphene.ObjectType):
         required=True)
     default_currency = graphene.String(
         description='Default shop\'s currency.', required=True)
+    default_country = graphene.Field(
+        CountryDisplay, description='Default shop\'s country')
     description = graphene.String(description='Shop\'s description.')
     domain = graphene.Field(
         Domain, required=True, description='Shop\'s domain data.')
@@ -144,3 +146,13 @@ def resolve_track_inventory_by_default(self, info):
 
     def resolve_default_weight_unit(self, info):
         return info.context.site.settings.default_weight_unit
+
+    def resolve_default_country(self, info):
+        default_country_code = settings.DEFAULT_COUNTRY
+        default_country_name = countries.countries.get(default_country_code)
+        if default_country_name:
+            default_country = CountryDisplay(
+                code=default_country_code, country=default_country_name)
+        else:
+            default_country = None
+        return default_country


Test patch:
diff --git a/tests/api/test_shop.py b/tests/api/test_shop.py
--- a/tests/api/test_shop.py
+++ b/tests/api/test_shop.py
@@ -261,3 +261,23 @@ def test_homepage_collection_update(admin_api_client, collection):
     assert data['homepageCollection']['name'] == collection.name
     site = Site.objects.get_current()
     assert site.settings.homepage_collection == collection
+
+
+def test_query_default_country(user_api_client, settings):
+    settings.DEFAULT_COUNTRY = 'US'
+    query = """
+    query {
+        shop {
+            defaultCountry {
+                code
+                country
+            }
+        }
+    }
+    """
+    response = user_api_client.post(reverse('api'), {'query': query})
+    content = get_graphql_content(response)
+    assert 'errors' not in content
+    data = content['data']['shop']['defaultCountry']
+    assert data['code'] == settings.DEFAULT_COUNTRY
+    assert data['country'] == 'United States of America'
Repository: saleor/saleor

Issue:
It's possible to reparent a product variant using the GraphQL mutation
Currently `productVariantCreate` and `productVariantUpdate` share the same input type.

This causes `productVariantCreate` to list `product` (an ID field) as optional (which is invalid).

It also causes `productVariantUpdate` to accept a new value for `product` which should be illegal as it would move a variant between two products.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -301,9 +301,6 @@ class ProductVariantInput(graphene.InputObjectType):
     cost_price = Decimal(description='Cost price of the variant.')
     price_override = Decimal(
         description='Special price of the particular variant.')
-    product = graphene.ID(
-        description='Product ID of which type is the variant.',
-        name='product')
     sku = graphene.String(description='Stock keeping unit.')
     quantity = graphene.Int(
         description='The total quantity of this variant available for sale.')
@@ -315,9 +312,15 @@ class ProductVariantInput(graphene.InputObjectType):
         description='Weight of the Product Variant.', required=False)
 
 
+class ProductVariantCreateInput(ProductVariantInput):
+    product = graphene.ID(
+        description='Product ID of which type is the variant.',
+        name='product', required=True)
+
+
 class ProductVariantCreate(ModelMutation):
     class Arguments:
-        input = ProductVariantInput(
+        input = ProductVariantCreateInput(
             required=True,
             description='Fields required to create a product variant.')
 


Test patch:
Repository: saleor/saleor

Issue:
It's possible to change the product's type using the GraphQL mutation
Currently `productCreate` and `productUpdate` share the same input type.

This causes `productCreate` to list `productType` (an ID field) as optional (not providing it is invalid).

It also causes `productUpdate` to accept a new value for `productType` which should be illegal as it could turn a book into a pair of jeans (and make all product and variant attributes invalid).


Discussion:

Resolving patch:
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -214,9 +214,6 @@ class ProductInput(graphene.InputObjectType):
     is_published = graphene.Boolean(
         description='Determines if product is visible to customers.')
     name = graphene.String(description='Product name.')
-    product_type = graphene.ID(
-        description='ID of the type that product belongs to.',
-        name='productType')
     price = Decimal(description='Product price.')
     tax_rate = TaxRateType(description='Tax rate.')
     seo = SeoInput(description='Search engine optimization fields.')
@@ -224,9 +221,15 @@ class ProductInput(graphene.InputObjectType):
         description='Weight of the Product.', required=False)
 
 
+class ProductCreateInput(ProductInput):
+    product_type = graphene.ID(
+        description='ID of the type that product belongs to.',
+        name='productType', required=True)
+
+
 class ProductCreate(ModelMutation):
     class Arguments:
-        input = ProductInput(
+        input = ProductCreateInput(
             required=True, description='Fields required to create a product.')
 
     class Meta:


Test patch:
Repository: saleor/saleor

Issue:
menuCreateItem input issue
Why `menuCreateItem` does not require `menu` argument on the schema level, but returns an error if not given? It doesn't look right. 
Besides, do we really need to specify `menu` argument, if `parent` is given? It's not like child could be pinned to different menu than its parent.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.py
--- a/saleor/graphql/menu/mutations.py
+++ b/saleor/graphql/menu/mutations.py
@@ -21,7 +21,8 @@ class MenuItemInput(graphene.InputObjectType):
 
 class MenuItemCreateInput(MenuItemInput):
     menu = graphene.ID(
-        description='Menu to which item belongs to.', name='menu')
+        description='Menu to which item belongs to.', name='menu',
+        required=True)
     parent = graphene.ID(
         description='''
         ID of the parent menu. If empty, menu will be top level


Test patch: