Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions google/api_core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ def _set_result_from_operation(self):
)
self.set_exception(exception)
else:
exception = exceptions.GoogleAPICallError(
"Unexpected state: Long-running operation had neither "
"response nor error set."
)
self.set_exception(exception)
# As per the link below, `Some services might not provide a result`.
# Neither `error` or `response`.
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
self.set_result(None)

def _refresh_and_update(self, retry=None):
"""Refresh the operation and update the result if needed.
Expand Down
9 changes: 4 additions & 5 deletions google/api_core/operation_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ def _set_result_from_operation(self):
)
self.set_exception(exception)
else:
exception = exceptions.GoogleAPICallError(
"Unexpected state: Long-running operation had neither "
"response nor error set."
)
self.set_exception(exception)
# As per the link below, `Some services might not provide a result`.
# Neither `error` or `response`.
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
self.set_result(None)

async def _refresh_and_update(self, retry=async_future.DEFAULT_RETRY):
"""Refresh the operation and update the result if needed.
Expand Down
9 changes: 6 additions & 3 deletions tests/asyncio/test_operation_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,20 @@ async def test_exception():

@mock.patch("asyncio.sleep", autospec=True)
@pytest.mark.asyncio
async def test_unexpected_result(unused_sleep):
async def test_no_result(unused_sleep):
# As per the link below, `Some services might not provide a result`.
# Neither `error` or `response`.
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
responses = [
make_operation_proto(),
# Second operation response is done, but has not error or response.
make_operation_proto(done=True),
]
future, _, _ = make_operation_future(responses)

exception = await future.exception()
response = await future.result()

assert "Unexpected state" in "{!r}".format(exception)
assert response is None


@pytest.mark.asyncio
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,20 @@ def test_exception_with_error_code():
assert isinstance(exception, exceptions.NotFound)


def test_unexpected_result():
def test_no_result():
# As per the link below, `Some services might not provide a result`.
# Neither `error` or `response`.
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
responses = [
make_operation_proto(),
# Second operation response is done, but has not error or response.
make_operation_proto(done=True),
]
future, _, _ = make_operation_future(responses)

exception = future.exception()
response = future.result()

assert "Unexpected state" in "{!r}".format(exception)
assert response is None


def test__refresh_http():
Expand Down