prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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`.
  
  </issue>
  <code>
  [start of saleor/product/forms.py]
  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 of saleor/product/forms.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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})
  
verification_info: {"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"}]}