Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show a non-None error for core_exception.Unknown errors. #968

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion google/cloud/ndb/_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def retry_wrapper(*args, **kwargs):
result = yield result
except exceptions.NestedRetryException as e:
error = e
except Exception as e:
except BaseException as e:
# `e` is removed from locals at end of block
error = e # See: https://goo.gl/5J8BMK

if not is_transient_error(error):
# If we are in an inner retry block, use special nested
# retry exception to bubble up to outer retry. Else, raise
Expand All @@ -104,6 +105,10 @@ def retry_wrapper(*args, **kwargs):

yield tasklets.sleep(sleep_time)

# Unknown errors really want to show up as None, so manually set the error.
if isinstance(error, core_exceptions.Unknown):
error = "google.api_core.exceptions.Unknown"

raise core_exceptions.RetryError(
"Maximum number of {} retries exceeded while calling {}".format(
retries, callback
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test__retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ def callback():
retry = _retry.retry_async(callback)
assert retry().exception() is error

@staticmethod
@pytest.mark.usefixtures("in_context")
def test_api_core_unknown():
def callback():
raise core_exceptions.Unknown("Unknown")

with pytest.raises(core_exceptions.RetryError) as e:
retry = _retry.retry_async(callback, retries=1)
retry().result()

assert e.value.cause == "google.api_core.exceptions.Unknown"

@staticmethod
@pytest.mark.usefixtures("in_context")
@mock.patch("google.cloud.ndb.tasklets.sleep")
Expand Down