From f2b583049e40a0a2762005e07dc7f5ca8fa4bf4c Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 1 Oct 2024 15:56:17 +0200 Subject: [PATCH] On github errors, retry once, and return a result or an exception This commit is meant to fix point 5. on analysis at https://gist.github.com/majamassarini/85033b59607a3f3da570cf5aaf2b8c7a raise_on_status (in urllib3.Retry) meaning is: Similar meaning to raise_on_redirect: whether we should raise an exception, or return a response, if status falls in status_forcelist range and retries have been exhausted. I would force to have or a result or an exception for not making Celery task hanging. --- ogr/services/github/service.py | 5 ++--- tests/unit/test_factory.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ogr/services/github/service.py b/ogr/services/github/service.py index b4452294..76d20a04 100644 --- a/ogr/services/github/service.py +++ b/ogr/services/github/service.py @@ -49,7 +49,7 @@ def __init__( github_app_private_key_path: Optional[str] = None, tokman_instance_url: Optional[str] = None, github_authentication: GithubAuthentication = None, - max_retries: Union[int, Retry] = 0, + max_retries: Union[int, Retry] = 1, **kwargs, ): """ @@ -69,12 +69,11 @@ def __init__( else: self._max_retries = Retry( total=int(max_retries), - read=0, # Retry mechanism active for these HTTP methods: allowed_methods=["DELETE", "GET", "PATCH", "POST", "PUT"], # Only retry on following HTTP status codes status_forcelist=[500, 503, 403, 401], - raise_on_status=False, + raise_on_status=True, ) if not self._default_auth_method: diff --git a/tests/unit/test_factory.py b/tests/unit/test_factory.py index 2de1e4c2..fa5583e1 100644 --- a/tests/unit/test_factory.py +++ b/tests/unit/test_factory.py @@ -465,7 +465,7 @@ def test_get_instances_from_dict_multiple_auth(instances_in_dict, result_instanc "token": "abcd", }, }, - 0, + 1, ), ( {