Skip to content

Commit

Permalink
fix 400 errors on retries in _call (#380)
Browse files Browse the repository at this point in the history
* fix 400 errors on retries in _call

The kwargs was being overwritten by ._get_args. If any retries are
needed, then on the second iteration datain will always be 'None'.  This
will cause uploading steps to return with exit code 400.

This commit fixes this bug by refactoring the _call method to minimize
the number of variabes in the scope.

Resolves #290

* rename to params for clarity
  • Loading branch information
nbren12 committed Apr 28, 2021
1 parent 74c0acd commit 60be1b9
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,27 @@ def _get_args(self, path, *args, **kwargs):
kwargs["userProject"] = user_project
return path, jsonin, datain, headers, kwargs

async def _request(self, method, path, *args, **kwargs):
await self._set_session()
self.maybe_refresh()
path, jsonin, datain, headers, params = self._get_args(path, *args, **kwargs)
async with self.session.request(
method=method,
url=path,
params=params,
json=jsonin,
headers=headers,
data=datain,
timeout=self.requests_timeout,
) as r:

status = r.status
headers = r.headers
info = r.request_info # for debug only
contents = await r.read()

return status, headers, info, contents

async def _call(
self, method, path, *args, json_out=False, info_out=False, **kwargs
):
Expand All @@ -507,26 +528,9 @@ async def _call(
try:
if retry > 0:
await asyncio.sleep(min(random.random() + 2 ** (retry - 1), 32))
self.maybe_refresh()
path, jsonin, datain, headers, kwargs = self._get_args(
path, *args, **kwargs
status, headers, info, contents = await self._request(
method, path, *args, **kwargs
)
await self._set_session()
async with self.session.request(
method=method,
url=path,
params=kwargs,
json=jsonin,
headers=headers,
data=datain,
timeout=self.requests_timeout,
) as r:

status = r.status
headers = r.headers
info = r.request_info # for debug only
contents = await r.read()

self.validate_response(status, contents, path, headers)
break
except (HttpError, RequestException, GoogleAuthError, ChecksumError) as e:
Expand Down

0 comments on commit 60be1b9

Please sign in to comment.