We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Improving product variant behaviour
### Steps to reproduce the problem

1. Choose any product in dashboard
2. Remove all variants
3. Try to go to the product page in storefront

### What I expected to happen

Product page in storefront with "UNAVAILABLE" label.

### What happened instead/how it failed
500 code. 


It is getting crashed with `list index out of range` error, because in method `update_field_data` in `VariantChoiceField` lines
```
        if self.queryset.count() < 2:
            self.widget = forms.HiddenInput(
                {'value': variants.all()[0].pk})
```
are trying to get index of empty query set.
Possible solution would be to omit this block of code if `variants.all()` is `False`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `saleor/product/forms.py`
Content:
```
1 import json
2 
3 from django import forms
4 from django.utils.encoding import smart_text
5 from django.utils.translation import pgettext_lazy
6 from django_prices.templatetags.prices_i18n import gross
7 
8 from ..cart.forms import AddToCartForm
9 
10 
11 class VariantChoiceField(forms.ModelChoiceField):
12     discounts = None
13 
14     def label_from_instance(self, obj):
15         variant_label = smart_text(obj)
16         label = pgettext_lazy(
17             'Variant choice field label',
18             '%(variant_label)s - %(price)s') % {
19                 'variant_label': variant_label,
20                 'price': gross(
21                     obj.get_price_per_item(discounts=self.discounts))}
22         return label
23 
24     def update_field_data(self, variants, cart):
25         """Initialize variant picker metadata."""
26         self.queryset = variants
27         self.discounts = cart.discounts
28         self.empty_label = None
29         images_map = {
30             variant.pk: [
31                 vi.image.image.url for vi in variant.variant_images.all()]
32             for variant in variants.all()}
33         self.widget.attrs['data-images'] = json.dumps(images_map)
34         # Don't display select input if there are less than two variants
35         if self.queryset.count() < 2:
36             self.widget = forms.HiddenInput(
37                 {'value': variants.all()[0].pk})
38 
39 
40 class ProductForm(AddToCartForm):
41     variant = VariantChoiceField(queryset=None)
42 
43     def __init__(self, *args, **kwargs):
44         super().__init__(*args, **kwargs)
45         variant_field = self.fields['variant']
46         variant_field.update_field_data(self.product.variants, self.cart)
47 
48     def get_variant(self, cleaned_data):
49         return cleaned_data.get('variant')
50
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/saleor/product/forms.py b/saleor/product/forms.py
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -31,8 +31,8 @@
                 vi.image.image.url for vi in variant.variant_images.all()]
             for variant in variants.all()}
         self.widget.attrs['data-images'] = json.dumps(images_map)
-        # Don't display select input if there are less than two variants
-        if self.queryset.count() < 2:
+        # Don't display select input if there is only one variant.
+        if self.queryset.count() == 1:
             self.widget = forms.HiddenInput(
                 {'value': variants.all()[0].pk})

{"golden_diff": "diff --git a/saleor/product/forms.py b/saleor/product/forms.py\n--- a/saleor/product/forms.py\n+++ b/saleor/product/forms.py\n@@ -31,8 +31,8 @@\n                 vi.image.image.url for vi in variant.variant_images.all()]\n             for variant in variants.all()}\n         self.widget.attrs['data-images'] = json.dumps(images_map)\n-        # Don't display select input if there are less than two variants\n-        if self.queryset.count() < 2:\n+        # Don't display select input if there is only one variant.\n+        if self.queryset.count() == 1:\n             self.widget = forms.HiddenInput(\n                 {'value': variants.all()[0].pk})\n", "issue": "Improving product variant behaviour\n### Steps to reproduce the problem\r\n\r\n1. Choose any product in dashboard\r\n2. Remove all variants\r\n3. Try to go to the product page in storefront\r\n\r\n### What I expected to happen\r\n\r\nProduct page in storefront with \"UNAVAILABLE\" label.\r\n\r\n### What happened instead/how it failed\r\n500 code. \r\n\r\n\r\nIt is getting crashed with `list index out of range` error, because in method `update_field_data` in `VariantChoiceField` lines\r\n```\r\n        if self.queryset.count() < 2:\r\n            self.widget = forms.HiddenInput(\r\n                {'value': variants.all()[0].pk})\r\n```\r\nare trying to get index of empty query set.\r\nPossible solution would be to omit this block of code if `variants.all()` is `False`.\n", "before_files": [{"content": "import json\n\nfrom django import forms\nfrom django.utils.encoding import smart_text\nfrom django.utils.translation import pgettext_lazy\nfrom django_prices.templatetags.prices_i18n import gross\n\nfrom ..cart.forms import AddToCartForm\n\n\nclass VariantChoiceField(forms.ModelChoiceField):\n    discounts = None\n\n    def label_from_instance(self, obj):\n        variant_label = smart_text(obj)\n        label = pgettext_lazy(\n            'Variant choice field label',\n            '%(variant_label)s - %(price)s') % {\n                'variant_label': variant_label,\n                'price': gross(\n                    obj.get_price_per_item(discounts=self.discounts))}\n        return label\n\n    def update_field_data(self, variants, cart):\n        \"\"\"Initialize variant picker metadata.\"\"\"\n        self.queryset = variants\n        self.discounts = cart.discounts\n        self.empty_label = None\n        images_map = {\n            variant.pk: [\n                vi.image.image.url for vi in variant.variant_images.all()]\n            for variant in variants.all()}\n        self.widget.attrs['data-images'] = json.dumps(images_map)\n        # Don't display select input if there are less than two variants\n        if self.queryset.count() < 2:\n            self.widget = forms.HiddenInput(\n                {'value': variants.all()[0].pk})\n\n\nclass ProductForm(AddToCartForm):\n    variant = VariantChoiceField(queryset=None)\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        variant_field = self.fields['variant']\n        variant_field.update_field_data(self.product.variants, self.cart)\n\n    def get_variant(self, cleaned_data):\n        return cleaned_data.get('variant')\n", "path": "saleor/product/forms.py"}], "after_files": [{"content": "import json\n\nfrom django import forms\nfrom django.utils.encoding import smart_text\nfrom django.utils.translation import pgettext_lazy\nfrom django_prices.templatetags.prices_i18n import gross\n\nfrom ..cart.forms import AddToCartForm\n\n\nclass VariantChoiceField(forms.ModelChoiceField):\n    discounts = None\n\n    def label_from_instance(self, obj):\n        variant_label = smart_text(obj)\n        label = pgettext_lazy(\n            'Variant choice field label',\n            '%(variant_label)s - %(price)s') % {\n                'variant_label': variant_label,\n                'price': gross(\n                    obj.get_price_per_item(discounts=self.discounts))}\n        return label\n\n    def update_field_data(self, variants, cart):\n        \"\"\"Initialize variant picker metadata.\"\"\"\n        self.queryset = variants\n        self.discounts = cart.discounts\n        self.empty_label = None\n        images_map = {\n            variant.pk: [\n                vi.image.image.url for vi in variant.variant_images.all()]\n            for variant in variants.all()}\n        self.widget.attrs['data-images'] = json.dumps(images_map)\n        # Don't display select input if there is only one variant.\n        if self.queryset.count() == 1:\n            self.widget = forms.HiddenInput(\n                {'value': variants.all()[0].pk})\n\n\nclass ProductForm(AddToCartForm):\n    variant = VariantChoiceField(queryset=None)\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        variant_field = self.fields['variant']\n        variant_field.update_field_data(self.product.variants, self.cart)\n\n    def get_variant(self, cleaned_data):\n        return cleaned_data.get('variant')\n", "path": "saleor/product/forms.py"}]}