prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Added retry on internal error
  Added retry on internal error as suggested by the internal error message: '500 Error encountered during execution. Retrying may solve the problem.'. 
  Rationalised the conditions structure so it would simplify addition of other retry conditions.
  
  </issue>
  <code>
  [start of bigquery/google/cloud/bigquery/retry.py]
  1 
  2 # Copyright 2018 Google LLC
  3 #
  4 # Licensed under the Apache License, Version 2.0 (the "License");
  5 # you may not use this file except in compliance with the License.
  6 # You may obtain a copy of the License at
  7 #
  8 #     http://www.apache.org/licenses/LICENSE-2.0
  9 #
  10 # Unless required by applicable law or agreed to in writing, software
  11 # distributed under the License is distributed on an "AS IS" BASIS,
  12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 # See the License for the specific language governing permissions and
  14 # limitations under the License.
  15 
  16 from google.api_core import retry
  17 
  18 
  19 def _should_retry(exc):
  20     """Predicate for determining when to retry.
  21 
  22     We retry if and only if the 'reason' is 'backendError'
  23     or 'rateLimitExceeded'.
  24     """
  25     if not hasattr(exc, 'errors'):
  26         return False
  27     if len(exc.errors) == 0:
  28         return False
  29     reason = exc.errors[0]['reason']
  30     return reason == 'backendError' or reason == 'rateLimitExceeded'
  31 
  32 
  33 DEFAULT_RETRY = retry.Retry(predicate=_should_retry)
  34 """The default retry object.
  35 
  36 Any method with a ``retry`` parameter will be retried automatically,
  37 with reasonable defaults. To disable retry, pass ``retry=None``.
  38 To modify the default retry behavior, call a ``with_XXX`` method
  39 on ``DEFAULT_RETRY``. For example, to change the deadline to 30 seconds,
  40 pass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.
  41 """
  42
  [end of bigquery/google/cloud/bigquery/retry.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/bigquery/google/cloud/bigquery/retry.py b/bigquery/google/cloud/bigquery/retry.py
  --- a/bigquery/google/cloud/bigquery/retry.py
  +++ b/bigquery/google/cloud/bigquery/retry.py
  @@ -16,6 +16,13 @@
   from google.api_core import retry
   
   
  +_RETRYABLE_REASONS = frozenset([
  +    'backendError',
  +    'rateLimitExceeded',
  +    'internalError',
  +])
  +
  +
   def _should_retry(exc):
       """Predicate for determining when to retry.
   
  @@ -27,7 +34,7 @@
       if len(exc.errors) == 0:
           return False
       reason = exc.errors[0]['reason']
  -    return reason == 'backendError' or reason == 'rateLimitExceeded'
  +    return reason in _RETRYABLE_REASONS
   
   
   DEFAULT_RETRY = retry.Retry(predicate=_should_retry)
  
verification_info: {"golden_diff": "diff --git a/bigquery/google/cloud/bigquery/retry.py b/bigquery/google/cloud/bigquery/retry.py\n--- a/bigquery/google/cloud/bigquery/retry.py\n+++ b/bigquery/google/cloud/bigquery/retry.py\n@@ -16,6 +16,13 @@\n from google.api_core import retry\n \n \n+_RETRYABLE_REASONS = frozenset([\n+    'backendError',\n+    'rateLimitExceeded',\n+    'internalError',\n+])\n+\n+\n def _should_retry(exc):\n     \"\"\"Predicate for determining when to retry.\n \n@@ -27,7 +34,7 @@\n     if len(exc.errors) == 0:\n         return False\n     reason = exc.errors[0]['reason']\n-    return reason == 'backendError' or reason == 'rateLimitExceeded'\n+    return reason in _RETRYABLE_REASONS\n \n \n DEFAULT_RETRY = retry.Retry(predicate=_should_retry)\n", "issue": "Added retry on internal error\nAdded retry on internal error as suggested by the internal error message: '500 Error encountered during execution. Retrying may solve the problem.'. \r\nRationalised the conditions structure so it would simplify addition of other retry conditions.\n", "before_files": [{"content": "\n# Copyright 2018 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom google.api_core import retry\n\n\ndef _should_retry(exc):\n    \"\"\"Predicate for determining when to retry.\n\n    We retry if and only if the 'reason' is 'backendError'\n    or 'rateLimitExceeded'.\n    \"\"\"\n    if not hasattr(exc, 'errors'):\n        return False\n    if len(exc.errors) == 0:\n        return False\n    reason = exc.errors[0]['reason']\n    return reason == 'backendError' or reason == 'rateLimitExceeded'\n\n\nDEFAULT_RETRY = retry.Retry(predicate=_should_retry)\n\"\"\"The default retry object.\n\nAny method with a ``retry`` parameter will be retried automatically,\nwith reasonable defaults. To disable retry, pass ``retry=None``.\nTo modify the default retry behavior, call a ``with_XXX`` method\non ``DEFAULT_RETRY``. For example, to change the deadline to 30 seconds,\npass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.\n\"\"\"\n", "path": "bigquery/google/cloud/bigquery/retry.py"}]}