From 891002171d4ad72e6aaf7c54102d4ca4f3bdb2fe Mon Sep 17 00:00:00 2001 From: Ben Pedigo Date: Mon, 23 Sep 2024 12:25:10 -0700 Subject: [PATCH] Rollback urllib3 pin (#237) * hotfix for urllib * remove test --- caveclient/session_config.py | 44 +++++++++++++++++++++++++++++------- requirements.txt | 2 +- tests/test_framework.py | 5 ---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/caveclient/session_config.py b/caveclient/session_config.py index e3234ae6..136f2be4 100644 --- a/caveclient/session_config.py +++ b/caveclient/session_config.py @@ -1,10 +1,18 @@ +import logging from typing import Collection, Optional, Union import requests +from packaging.version import Version +from urllib3 import __version__ as urllib3_version from urllib3.util.retry import Retry SESSION_DEFAULTS = {} +if Version(urllib3_version) < Version("2.0.0"): + HAS_URLLIB3_V2 = False +else: + HAS_URLLIB3_V2 = True + def set_session_defaults( max_retries: int = 3, @@ -78,6 +86,17 @@ def set_session_defaults( SESSION_DEFAULTS["backoff_max"] = backoff_max SESSION_DEFAULTS["status_forcelist"] = status_forcelist + if not HAS_URLLIB3_V2 and backoff_max != 120: + logging.warning( + ( + "`backoff_max` is only supported in urllib3 v2.0.0 and above " + "and will be ignored. " + "Please upgrade urllib3 to take advantage of this feature. " + "Note that this upgrade may conflict with other packages that depend on " + "urllib3, including `cloud-volume`." + ) + ) + set_session_defaults() @@ -119,14 +138,23 @@ def _patch_session( if pool_maxsize is None: pool_maxsize = SESSION_DEFAULTS["pool_maxsize"] - retries = Retry( - total=max_retries, - backoff_factor=SESSION_DEFAULTS["backoff_factor"], - status_forcelist=SESSION_DEFAULTS["status_forcelist"], - allowed_methods=frozenset(["GET", "POST"]), - backoff_max=SESSION_DEFAULTS["backoff_max"], - raise_on_status=False, - ) + if HAS_URLLIB3_V2: + retries = Retry( + total=max_retries, + backoff_factor=SESSION_DEFAULTS["backoff_factor"], + status_forcelist=SESSION_DEFAULTS["status_forcelist"], + allowed_methods=frozenset(["GET", "POST"]), + raise_on_status=False, + ) + else: + retries = Retry( + total=max_retries, + backoff_factor=SESSION_DEFAULTS["backoff_factor"], + status_forcelist=SESSION_DEFAULTS["status_forcelist"], + allowed_methods=frozenset(["GET", "POST"]), + backoff_max=SESSION_DEFAULTS["backoff_max"], + raise_on_status=False, + ) http = requests.adapters.HTTPAdapter( pool_maxsize=pool_maxsize, diff --git a/requirements.txt b/requirements.txt index e59853ab..3a9716cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ numpy<2.0.0 pyarrow>=3 requests -urllib3>=2.0.2 +urllib3 pandas<3.0.0 cachetools>=4.2.1 ipython diff --git a/tests/test_framework.py b/tests/test_framework.py index cc882ddf..82c150cb 100644 --- a/tests/test_framework.py +++ b/tests/test_framework.py @@ -125,7 +125,6 @@ def test_set_session_defaults(self): pool_block = True max_retries = 5 backoff_factor = 0.5 - backoff_max = 240 status_forcelist = (502, 503, 504, 505) set_session_defaults( @@ -133,7 +132,6 @@ def test_set_session_defaults(self): pool_block=pool_block, max_retries=max_retries, backoff_factor=backoff_factor, - backoff_max=backoff_max, status_forcelist=status_forcelist, ) client = CAVEclient( @@ -148,9 +146,6 @@ def test_set_session_defaults(self): client.l2cache.session.adapters["https://"].max_retries.backoff_factor == 0.5 ) - assert ( - client.l2cache.session.adapters["https://"].max_retries.backoff_max == 240 - ) assert client.l2cache.session.adapters[ "https://" ].max_retries.status_forcelist == (