File tree 4 files changed +15
-17
lines changed
4 files changed +15
-17
lines changed Original file line number Diff line number Diff line change @@ -140,11 +140,11 @@ def _set_result_from_operation(self):
140
140
)
141
141
self .set_exception (exception )
142
142
else :
143
- exception = exceptions . GoogleAPICallError (
144
- "Unexpected state: Long-running operation had neither "
145
- "response nor error set."
146
- )
147
- self .set_exception ( exception )
143
+ # Some APIs set `done: true`, with an empty response.
144
+ # Set the result to an empty message of the expected
145
+ # result type.
146
+ # https://google.aip.dev/151
147
+ self .set_result ( self . _result_type () )
148
148
149
149
def _refresh_and_update (self , retry = polling .DEFAULT_RETRY ):
150
150
"""Refresh the operation and update the result if needed.
Original file line number Diff line number Diff line change @@ -136,11 +136,11 @@ def _set_result_from_operation(self):
136
136
)
137
137
self .set_exception (exception )
138
138
else :
139
- exception = exceptions . GoogleAPICallError (
140
- "Unexpected state: Long-running operation had neither "
141
- "response nor error set."
142
- )
143
- self .set_exception ( exception )
139
+ # Some APIs set `done: true`, with an empty response.
140
+ # Set the result to an empty message of the expected
141
+ # result type.
142
+ # https://google.aip.dev/151
143
+ self .set_result ( self . _result_type () )
144
144
145
145
async def _refresh_and_update (self , retry = async_future .DEFAULT_RETRY ):
146
146
"""Refresh the operation and update the result if needed.
Original file line number Diff line number Diff line change @@ -153,17 +153,17 @@ async def test_exception():
153
153
154
154
@mock .patch ("asyncio.sleep" , autospec = True )
155
155
@pytest .mark .asyncio
156
- async def test_unexpected_result (unused_sleep ):
156
+ async def test_done_with_no_error_or_response (unused_sleep ):
157
157
responses = [
158
158
make_operation_proto (),
159
159
# Second operation response is done, but has not error or response.
160
160
make_operation_proto (done = True ),
161
161
]
162
162
future , _ , _ = make_operation_future (responses )
163
163
164
- exception = await future .exception ()
164
+ result = await future .result ()
165
165
166
- assert "Unexpected state" in "{!r}" . format ( exception )
166
+ assert isinstance ( result , struct_pb2 . Struct )
167
167
168
168
169
169
def test_from_gapic ():
Original file line number Diff line number Diff line change @@ -163,17 +163,15 @@ def test_exception_with_error_code():
163
163
assert isinstance (exception , exceptions .NotFound )
164
164
165
165
166
- def test_unexpected_result ():
166
+ def test_done_with_no_error_or_response ():
167
167
responses = [
168
168
make_operation_proto (),
169
169
# Second operation response is done, but has not error or response.
170
170
make_operation_proto (done = True ),
171
171
]
172
172
future , _ , _ = make_operation_future (responses )
173
173
174
- exception = future .exception ()
175
-
176
- assert "Unexpected state" in "{!r}" .format (exception )
174
+ assert isinstance (future .result (), struct_pb2 .Struct )
177
175
178
176
179
177
def test__refresh_http ():
You can’t perform that action at this time.
0 commit comments