From 8a388e2c6eacee473fad28e99366e36c443dfe40 Mon Sep 17 00:00:00 2001 From: "Noah D. Brenowitz" Date: Tue, 27 Apr 2021 19:53:08 -0700 Subject: [PATCH 1/2] 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 --- gcsfs/core.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/gcsfs/core.py b/gcsfs/core.py index 38e51b9a..8b493818 100644 --- a/gcsfs/core.py +++ b/gcsfs/core.py @@ -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, kwargs = self._get_args(path, *args, **kwargs) + 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() + + return status, headers, info, contents + async def _call( self, method, path, *args, json_out=False, info_out=False, **kwargs ): @@ -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: From 7c52fc3f5d52ad9c17f086c676996b3ff507cd98 Mon Sep 17 00:00:00 2001 From: "Noah D. Brenowitz" Date: Tue, 27 Apr 2021 20:47:44 -0700 Subject: [PATCH 2/2] rename to params for clarity --- gcsfs/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcsfs/core.py b/gcsfs/core.py index 8b493818..b4e73b06 100644 --- a/gcsfs/core.py +++ b/gcsfs/core.py @@ -501,11 +501,11 @@ def _get_args(self, path, *args, **kwargs): async def _request(self, method, path, *args, **kwargs): await self._set_session() self.maybe_refresh() - path, jsonin, datain, headers, kwargs = self._get_args(path, *args, **kwargs) + path, jsonin, datain, headers, params = self._get_args(path, *args, **kwargs) async with self.session.request( method=method, url=path, - params=kwargs, + params=params, json=jsonin, headers=headers, data=datain,