Skip to content

Commit

Permalink
Rollback urllib3 pin (#237)
Browse files Browse the repository at this point in the history
* hotfix for urllib

* remove test
  • Loading branch information
bdpedigo authored Sep 23, 2024
1 parent 40f1e56 commit 8910021
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
44 changes: 36 additions & 8 deletions caveclient/session_config.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ 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(
pool_maxsize=pool_maxsize,
pool_block=pool_block,
max_retries=max_retries,
backoff_factor=backoff_factor,
backoff_max=backoff_max,
status_forcelist=status_forcelist,
)
client = CAVEclient(
Expand All @@ -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 == (
Expand Down

0 comments on commit 8910021

Please sign in to comment.