Skip to content

Commit 6ccb4ad

Browse files
authored
[rest] correctly pickle rest aiohttp responses (Azure#20577)
1 parent 84bd0e9 commit 6ccb4ad

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

sdk/core/azure-core/azure/core/rest/_aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def iter_bytes(self) -> AsyncIterator[bytes]:
155155
def __getstate__(self):
156156
state = self.__dict__.copy()
157157
# Remove the unpicklable entries.
158-
state['internal_response'] = None # aiohttp response are not pickable (see headers comments)
158+
state['_internal_response'] = None # aiohttp response are not pickable (see headers comments)
159159
state['headers'] = CIMultiDict(self.headers) # MultiDictProxy is not pickable
160160
return state
161161

sdk/core/azure-core/tests/async_tests/test_rest_polling_async.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,16 @@ async def test_delete_operation_location(lro_poller):
118118
async def test_request_id(lro_poller):
119119
result = await (await lro_poller(HttpRequest("POST", "/polling/request-id"), request_id="123456789")).result()
120120
assert result['status'] == "Succeeded"
121+
122+
@pytest.mark.asyncio
123+
async def test_continuation_token(client, lro_poller, deserialization_callback):
124+
poller = await lro_poller(HttpRequest("POST", "/polling/post/location-and-operation-location"))
125+
token = poller.continuation_token()
126+
new_poller = AsyncLROPoller.from_continuation_token(
127+
continuation_token=token,
128+
polling_method=AsyncLROBasePolling(0),
129+
client=client._client,
130+
deserialization_callback=deserialization_callback,
131+
)
132+
result = await new_poller.result()
133+
assert result == {'location_result': True}

sdk/core/azure-core/tests/test_rest_polling.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ def test_delete_operation_location(lro_poller):
104104

105105
def test_request_id(lro_poller):
106106
result = lro_poller(HttpRequest("POST", "/polling/request-id"), request_id="123456789").result()
107+
108+
def test_continuation_token(client, lro_poller, deserialization_callback):
109+
poller = lro_poller(HttpRequest("POST", "/polling/post/location-and-operation-location"))
110+
token = poller.continuation_token()
111+
new_poller = LROPoller.from_continuation_token(
112+
continuation_token=token,
113+
polling_method=LROBasePolling(0),
114+
client=client._client,
115+
deserialization_callback=deserialization_callback,
116+
)
117+
result = new_poller.result()
118+
assert result == {'location_result': True}

0 commit comments

Comments
 (0)