Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't retry on 400 #1515

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions osc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,20 @@ def http_request_wrap_file(func):
Turn file path into a file object and close it automatically
by using a context manager.
"""
def new_func(method, url, headers=None, data=None, file=None, retry_on_400: bool = True):
def new_func(method, url, headers=None, data=None, file=None):
if file:
with open(file, "rb") as f:
return func(method, url, headers, data, f, retry_on_400)
return func(method, url, headers, data, file=f)
else:
return func(method, url, headers, data, file, retry_on_400)
return func(method, url, headers, data, file)

new_func.__name__ = func.__name__
new_func.__doc__ = func.__doc__
return new_func


@http_request_wrap_file
def http_request(method: str, url: str, headers=None, data=None, file=None, retry_on_400: bool = True):
def http_request(method: str, url: str, headers=None, data=None, file=None):
"""
Send a HTTP request to a server.

Expand All @@ -174,7 +174,6 @@ def http_request(method: str, url: str, headers=None, data=None, file=None, retr
:param headers: Dictionary of custom headers to send.
:param data: Data to send in the request body (conflicts with `file`).
:param file: Path to a file to send as data in the request body (conflicts with `data`).
:param retry_on_400: Whether to retry on receiving HTTP status code 400.
"""

purl = urllib3.util.parse_url(url)
Expand Down Expand Up @@ -234,22 +233,15 @@ def http_request(method: str, url: str, headers=None, data=None, file=None, retr
else:
retries_kwargs = {"method_whitelist": None}


status_forcelist = (
500, # Internal Server Error
502, # Bad Gateway
503, # Service Unavailable
504, # Gateway Timeout
)
if retry_on_400:
status_forcelist = (
400, # Bad Request; retry on 400: service in progress
) + status_forcelist

pool_kwargs["retries"] = urllib3.Retry(
total=int(conf.config["http_retries"]),
backoff_factor=2,
status_forcelist=status_forcelist,
status_forcelist=(
500, # Internal Server Error
502, # Bad Gateway
503, # Service Unavailable
504, # Gateway Timeout
),
# don't raise because we want an actual response rather than a MaxRetryError with "too many <status_code> error responses" message
raise_on_status=False,
**retries_kwargs,
Expand Down
2 changes: 1 addition & 1 deletion osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5422,7 +5422,7 @@ def server_diff(
query["file"] = UrlQueryArray(files)

u = makeurl(apiurl, ['source', new_project, new_package], query=query)
f = http_POST(u, retry_on_400=False)
f = http_POST(u)
if onlyissues and not xml:
del_issue_list = []
add_issue_list = []
Expand Down
2 changes: 1 addition & 1 deletion osc/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@
from ..core import makeurl
url = makeurl(apiurl, path, query)
# TODO: catch HTTPError and return the wrapped response as XmlModel instance
return http_request(method, url, data=data, retry_on_400=False)
return http_request(method, url, data=data)

Check warning on line 762 in osc/util/models.py

View check run for this annotation

Codecov / codecov/patch

osc/util/models.py#L762

Added line #L762 was not covered by tests

def do_update(self, other: "XmlModel") -> None:
"""
Expand Down
Loading