prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [BUG] could not serialize access due to concurrent update
  could not serialize access due to concurrent update
  
  and just crash....
  
  </issue>
  <code>
  [start of InvenTree/InvenTree/exchange.py]
  1 from common.settings import currency_code_default, currency_codes
  2 from urllib.error import HTTPError, URLError
  3 
  4 from djmoney.contrib.exchange.backends.base import SimpleExchangeBackend
  5 
  6 
  7 class InvenTreeExchange(SimpleExchangeBackend):
  8     """
  9     Backend for automatically updating currency exchange rates.
  10 
  11     Uses the exchangerate.host service API
  12     """
  13 
  14     name = "InvenTreeExchange"
  15 
  16     def __init__(self):
  17         self.url = "https://api.exchangerate.host/latest"
  18 
  19         super().__init__()
  20 
  21     def get_params(self):
  22         # No API key is required
  23         return {
  24         }
  25 
  26     def update_rates(self, base_currency=currency_code_default()):
  27 
  28         symbols = ','.join(currency_codes())
  29 
  30         try:
  31             super().update_rates(base=base_currency, symbols=symbols)
  32         # catch connection errors
  33         except (HTTPError, URLError):
  34             print('Encountered connection error while updating')
  35
  [end of InvenTree/InvenTree/exchange.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/InvenTree/InvenTree/exchange.py b/InvenTree/InvenTree/exchange.py
  --- a/InvenTree/InvenTree/exchange.py
  +++ b/InvenTree/InvenTree/exchange.py
  @@ -2,6 +2,7 @@
   from urllib.error import HTTPError, URLError
   
   from djmoney.contrib.exchange.backends.base import SimpleExchangeBackend
  +from django.db.utils import OperationalError
   
   
   class InvenTreeExchange(SimpleExchangeBackend):
  @@ -32,3 +33,12 @@
           # catch connection errors
           except (HTTPError, URLError):
               print('Encountered connection error while updating')
  +        except OperationalError as e:
  +            if 'SerializationFailure' in e.__cause__.__class__.__name__:
  +                print('Serialization Failure while updating exchange rates')
  +                # We are just going to swallow this exception because the
  +                # exchange rates will be updated later by the scheduled task
  +            else:
  +                # Other operational errors probably are still show stoppers
  +                # so reraise them so that the log contains the stacktrace
  +                raise
  
verification_info: {"golden_diff": "diff --git a/InvenTree/InvenTree/exchange.py b/InvenTree/InvenTree/exchange.py\n--- a/InvenTree/InvenTree/exchange.py\n+++ b/InvenTree/InvenTree/exchange.py\n@@ -2,6 +2,7 @@\n from urllib.error import HTTPError, URLError\n \n from djmoney.contrib.exchange.backends.base import SimpleExchangeBackend\n+from django.db.utils import OperationalError\n \n \n class InvenTreeExchange(SimpleExchangeBackend):\n@@ -32,3 +33,12 @@\n         # catch connection errors\n         except (HTTPError, URLError):\n             print('Encountered connection error while updating')\n+        except OperationalError as e:\n+            if 'SerializationFailure' in e.__cause__.__class__.__name__:\n+                print('Serialization Failure while updating exchange rates')\n+                # We are just going to swallow this exception because the\n+                # exchange rates will be updated later by the scheduled task\n+            else:\n+                # Other operational errors probably are still show stoppers\n+                # so reraise them so that the log contains the stacktrace\n+                raise\n", "issue": "[BUG] could not serialize access due to concurrent update\ncould not serialize access due to concurrent update\r\n\r\nand just crash....\n", "before_files": [{"content": "from common.settings import currency_code_default, currency_codes\nfrom urllib.error import HTTPError, URLError\n\nfrom djmoney.contrib.exchange.backends.base import SimpleExchangeBackend\n\n\nclass InvenTreeExchange(SimpleExchangeBackend):\n    \"\"\"\n    Backend for automatically updating currency exchange rates.\n\n    Uses the exchangerate.host service API\n    \"\"\"\n\n    name = \"InvenTreeExchange\"\n\n    def __init__(self):\n        self.url = \"https://api.exchangerate.host/latest\"\n\n        super().__init__()\n\n    def get_params(self):\n        # No API key is required\n        return {\n        }\n\n    def update_rates(self, base_currency=currency_code_default()):\n\n        symbols = ','.join(currency_codes())\n\n        try:\n            super().update_rates(base=base_currency, symbols=symbols)\n        # catch connection errors\n        except (HTTPError, URLError):\n            print('Encountered connection error while updating')\n", "path": "InvenTree/InvenTree/exchange.py"}]}