Skip to content

Commit eb4eaa1

Browse files
authored
Merge pull request #667 from superannotateai/fix_aioclient
fix AIOHttpSession retry
2 parents 5a1a404 + 6b684d7 commit eb4eaa1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/superannotate/lib/infrastructure/services/annotation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ async def _sync_large_annotation(self, team_id, project_id, item_id):
8080
async with AIOHttpSession(
8181
connector=aiohttp.TCPConnector(ssl=False),
8282
headers=self.client.default_headers,
83+
raise_for_status=True,
8384
) as session:
8485
_response = await session.request("post", sync_url, params=sync_params)
85-
_response.raise_for_status()
8686
sync_params.pop("current_source")
8787
sync_params.pop("desired_source")
8888

@@ -123,9 +123,9 @@ async def get_big_annotation(
123123
async with AIOHttpSession(
124124
connector=aiohttp.TCPConnector(ssl=False),
125125
headers=self.client.default_headers,
126+
raise_for_status=True,
126127
) as session:
127128
start_response = await session.request("post", url, params=query_params)
128-
start_response.raise_for_status()
129129
large_annotation = await start_response.json()
130130

131131
reporter.update_progress()
@@ -206,9 +206,9 @@ async def download_big_annotation(
206206
async with AIOHttpSession(
207207
connector=aiohttp.TCPConnector(ssl=False),
208208
headers=self.client.default_headers,
209+
raise_for_status=True,
209210
) as session:
210211
start_response = await session.request("post", url, params=query_params)
211-
start_response.raise_for_status()
212212
res = await start_response.json()
213213
Path(download_path).mkdir(exist_ok=True, parents=True)
214214

src/superannotate/lib/infrastructure/services/http_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ async def request(self, *args, **kwargs) -> aiohttp.ClientResponse:
251251
response = await super()._request(*args, **kwargs)
252252
if attempts <= 1 or response.status not in self.RETRY_STATUS_CODES:
253253
return response
254+
if isinstance(kwargs["data"], aiohttp.FormData):
255+
raise RuntimeError(await response.text())
254256
except (aiohttp.ClientError, RuntimeError) as e:
255257
if attempts <= 1:
256258
raise
257-
if isinstance(e, RuntimeError):
258-
data = kwargs["data"]
259-
if isinstance(data, aiohttp.FormData):
260-
kwargs["data"] = self._copy_form_data(data)
259+
data = kwargs["data"]
260+
if isinstance(data, aiohttp.FormData):
261+
kwargs["data"] = self._copy_form_data(data)
261262
attempts -= 1
262263
await asyncio.sleep(delay)

0 commit comments

Comments
 (0)