Skip to content

Commit e716136

Browse files
authored
Add version check for urllib3 in backoff calculation (databricks#526)
Signed-off-by: Shivam Raj <[email protected]>
1 parent fbaa451 commit e716136

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/databricks/sql/auth/retry.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from enum import Enum
66
from typing import List, Optional, Tuple, Union
77

8+
import urllib3
9+
810
# We only use this import for type hinting
911
try:
1012
# If urllib3~=2.0 is installed
@@ -14,6 +16,8 @@
1416
from urllib3 import HTTPResponse as BaseHTTPResponse
1517
from urllib3 import Retry
1618
from urllib3.util.retry import RequestHistory
19+
from packaging import version
20+
1721

1822
from databricks.sql.exc import (
1923
CursorAlreadyClosedError,
@@ -308,8 +312,9 @@ def get_backoff_time(self) -> float:
308312

309313
current_attempt = self.stop_after_attempts_count - int(self.total or 0)
310314
proposed_backoff = (2**current_attempt) * self.delay_min
311-
if self.backoff_jitter != 0.0:
312-
proposed_backoff += random.random() * self.backoff_jitter
315+
if version.parse(urllib3.__version__) >= version.parse("2.0.0"):
316+
if self.backoff_jitter != 0.0:
317+
proposed_backoff += random.random() * self.backoff_jitter
313318

314319
proposed_backoff = min(proposed_backoff, self.delay_max)
315320
self.check_proposed_wait(proposed_backoff)

0 commit comments

Comments
 (0)