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: consume part of StreamingResponseIterator to support failure while under a retry context #10206

Merged
merged 7 commits into from
Jan 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: lint adjust
  • Loading branch information
crwilcox committed Jan 27, 2020
commit d2271dd195d93a222675480a14d370e205884e3f
5 changes: 2 additions & 3 deletions api_core/google/api_core/grpc_helpers.py
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ def __init__(self, wrapped):
self._wrapped = wrapped

# This iterator is used in a retry context, and returned outside after init.
# gRPC will not throw an exception until the stream is consumed, so we need
# gRPC will not throw an exception until the stream is consumed, so we need
# to retrieve the first result, in order to fail, in order to trigger a retry.
try:
self._stored_first_result = six.next(self._wrapped)
@@ -78,7 +78,6 @@ def __init__(self, wrapped):
# ignore stop iteration at this time. This should be handled outside of retry.
pass


def __iter__(self):
"""This iterator is also an iterable that returns itself."""
return self
@@ -96,7 +95,7 @@ def next(self):
return result
return six.next(self._wrapped)
except grpc.RpcError as exc:
# If the stream has already returned data, we cannot recover here.
# If the stream has already returned data, we cannot recover here.
six.raise_from(exceptions.from_grpc_error(exc), exc)

# Alias needed for Python 2/3 support.
3 changes: 1 addition & 2 deletions api_core/tests/unit/test_grpc_helpers.py
Original file line number Diff line number Diff line change
@@ -88,7 +88,6 @@ def test_wrap_stream_iterable_iterface():

got_iterator = wrapped_callable()


callable_.assert_called_once_with()

# Check each aliased method in the grpc.Call interface
@@ -148,7 +147,7 @@ def test_wrap_stream_errors_iterator():
wrapped_callable = grpc_helpers._wrap_stream_errors(callable_)

with pytest.raises(exceptions.ServiceUnavailable) as exc_info:
got_iterator = wrapped_callable(1, 2, three="four")
wrapped_callable(1, 2, three="four")

callable_.assert_called_once_with(1, 2, three="four")
assert exc_info.value.response == grpc_error