Skip to content

Commit 9c02633

Browse files
committed
fix: change argument name and set as suggested
1 parent 4f30ec5 commit 9c02633

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

gitlab/client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Gitlab:
6666
user_agent: A custom user agent to use for making HTTP requests.
6767
retry_transient_errors: Whether to retry after 500, 502, 503, 504
6868
or 52x responses. Defaults to False.
69-
persist_base_url: reconstruct next url if found not same as user provided url
69+
keep_base_url: keep user-provided base URL for pagination if it
70+
differs from response headers
7071
"""
7172

7273
def __init__(
@@ -86,7 +87,7 @@ def __init__(
8687
order_by: Optional[str] = None,
8788
user_agent: str = gitlab.const.USER_AGENT,
8889
retry_transient_errors: bool = False,
89-
persist_base_url: bool = False,
90+
keep_base_url: bool = False,
9091
) -> None:
9192

9293
self._api_version = str(api_version)
@@ -97,7 +98,7 @@ def __init__(
9798
#: Timeout to use for requests to gitlab server
9899
self.timeout = timeout
99100
self.retry_transient_errors = retry_transient_errors
100-
self.persist_base_url = persist_base_url
101+
self.keep_base_url = keep_base_url
101102
#: Headers that will be used in request to GitLab
102103
self.headers = {"User-Agent": user_agent}
103104

@@ -1143,19 +1144,20 @@ def _query(
11431144
search_api_url = re.search(r"(^.*?/api)", next_url)
11441145
if search_api_url:
11451146
next_api_url = search_api_url.group(1)
1146-
if self._gl.persist_base_url:
1147+
if self._gl.keep_base_url:
11471148
next_url = next_url.replace(
11481149
next_api_url, f"{self._gl._base_url}/api"
11491150
)
11501151
else:
11511152
utils.warn(
11521153
message=(
1153-
f"The base url of the returned next page got "
1154-
f"different with the user provided "
1155-
f"{self._gl.url}/api* ~> {next_api_url}*, "
1156-
f"since this may can lead to unexpected behaviour. "
1157-
f"set argument persist_base_url to True for "
1158-
f"resonctruct it with the origin one."
1154+
f"The base URL in the server response"
1155+
f"differs from the user-provided base URL "
1156+
f"({self._gl.url}/api/ -> {next_api_url}/). "
1157+
f"This may lead to unexpected behavior and "
1158+
f"broken pagination. Use `keep_base_url=True` "
1159+
f"when initializing the Gitlab instance "
1160+
f"to follow the user-provided base URL."
11591161
),
11601162
category=UserWarning,
11611163
)

tests/unit/test_gitlab.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,30 +359,28 @@ def test_gitlab_plain_const_does_not_warn(recwarn):
359359
@pytest.mark.parametrize(
360360
"kwargs,link_header,expected_next_url,show_warning",
361361
[
362-
# normal execution
363362
(
364363
{},
365364
"<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"',
366365
"http://localhost/api/v4/tests?per_page=1&page=2",
367366
False,
368367
),
369-
# got different url and will show the warning
370368
(
371369
{},
372370
"<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"',
373371
"http://orig_host/api/v4/tests?per_page=1&page=2",
374372
True,
375373
),
376-
# persist the base url
377374
(
378-
{"persist_base_url": True},
375+
{"keep_base_url": True},
379376
"<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"',
380377
"http://localhost/api/v4/tests?per_page=1&page=2",
381378
False,
382379
),
383380
],
381+
ids=["url-match-does-not-warn", "url-mismatch-warns", "url-mismatch-keeps-url"],
384382
)
385-
def test_gitlab_persist_base_url(kwargs, link_header, expected_next_url, show_warning):
383+
def test_gitlab_keep_base_url(kwargs, link_header, expected_next_url, show_warning):
386384
responses.add(
387385
**{
388386
"method": responses.GET,

0 commit comments

Comments
 (0)