Skip to content

Commit 2383492

Browse files
authored
fix: only append kwargs as query parameters
Some arguments to `http_request` were being read from kwargs, but kwargs is where this function creates query parameters from, by default. In the absence of a `query_parameters` param, the function would construct URLs with query parameters such as `retry_transient_errors=True` despite those parameters having no meaning to the API to which the request was sent. This change names those arguments that are specific to `http_request` so that they do not end up as query parameters read from kwargs.
1 parent 3265873 commit 2383492

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

gitlab/client.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ def http_request(
451451
post_data: Optional[Dict[str, Any]] = None,
452452
streamed: bool = False,
453453
files: Optional[Dict[str, Any]] = None,
454+
timeout: Optional[float] = None,
455+
obey_rate_limit: bool = True,
456+
retry_transient_errors: bool = False,
457+
max_retries: int = 10,
454458
**kwargs: Any,
455459
) -> requests.Response:
456460
"""Make an HTTP request to the Gitlab server.
@@ -465,6 +469,14 @@ def http_request(
465469
json)
466470
streamed (bool): Whether the data should be streamed
467471
files (dict): The files to send to the server
472+
timeout (float): The timeout, in seconds, for the request
473+
obey_rate_limit (bool): Whether to obey 429 Too Many Request
474+
responses. Defaults to True.
475+
retry_transient_errors (bool): Whether to retry after 500, 502,
476+
503, or 504 responses. Defaults
477+
to False.
478+
max_retries (int): Max retries after 429 or transient errors,
479+
set to -1 to retry forever. Defaults to 10.
468480
**kwargs: Extra options to send to the server (e.g. sudo)
469481
470482
Returns:
@@ -496,9 +508,10 @@ def http_request(
496508
opts = self._get_session_opts(content_type="application/json")
497509

498510
verify = opts.pop("verify")
499-
timeout = opts.pop("timeout")
511+
opts_timeout = opts.pop("timeout")
500512
# If timeout was passed into kwargs, allow it to override the default
501-
timeout = kwargs.get("timeout", timeout)
513+
if timeout is None:
514+
timeout = opts_timeout
502515

503516
# We need to deal with json vs. data when uploading files
504517
if files:
@@ -526,15 +539,7 @@ def http_request(
526539
prepped.url, {}, streamed, verify, None
527540
)
528541

529-
# obey the rate limit by default
530-
obey_rate_limit = kwargs.get("obey_rate_limit", True)
531-
# do not retry transient errors by default
532-
retry_transient_errors = kwargs.get("retry_transient_errors", False)
533-
534-
# set max_retries to 10 by default, disable by setting it to -1
535-
max_retries = kwargs.get("max_retries", 10)
536542
cur_retries = 0
537-
538543
while True:
539544
result = self.session.send(prepped, timeout=timeout, **settings)
540545

0 commit comments

Comments
 (0)