Skip to content

Commit a918f13

Browse files
author
Jesse
authored
Make backwards compatible with urllib3~=1.0 [Follow up #197] (#206)
* Make retry policy backwards compatible with urllib3~=1.0.0 We already implement the equivalent of backoff_max so the behaviour will be the same for urllib3==1.x and urllib3==2.x We do not implement backoff jitter so the behaviour for urllib3==1.x will NOT include backoff jitter whereas urllib3==2.x WILL include jitter. --------- Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent a072574 commit a918f13

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

CHANGELOG.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# Release History
22

3-
## 2.9.x (Unreleased)
3+
## 2.9.4 (Unreleased)
4+
5+
## 2.9.3 (2023-08-24)
6+
7+
- Fix: Connections failed when urllib3~=1.0.0 is installed (#206)
48

59
## 2.9.2 (2023-08-17)
610

7-
- Other: Add `examples/v3_retries_query_execute.py`
8-
- Other: suppress log message when `_enable_v3_retries` is not `True`
9-
- Other: make this connector backwards compatible with `urllib3>=1.0.0`
11+
- Other: Add `examples/v3_retries_query_execute.py` (#199)
12+
- Other: suppress log message when `_enable_v3_retries` is not `True` (#199)
13+
- Other: make this connector backwards compatible with `urllib3>=1.0.0` (#197)
1014

1115
## 2.9.1 (2023-08-11)
1216

13-
- Other: Explicitly pin urllib3 to ^2.0.0
17+
- Other: Explicitly pin urllib3 to ^2.0.0 (#191)
1418

1519
## 2.9.0 (2023-08-10)
1620

17-
- Replace retry handling with DatabricksRetryPolicy. This is disabled by default. To enable, set `enable_v3_retries=True` when creating `databricks.sql.client`
18-
- Other: Fix typo in README quick start example
19-
- Other: Add autospec to Client mocks and tidy up `make_request`
21+
- Replace retry handling with DatabricksRetryPolicy. This is disabled by default. To enable, set `enable_v3_retries=True` when creating `databricks.sql.client` (#182)
22+
- Other: Fix typo in README quick start example (#186)
23+
- Other: Add autospec to Client mocks and tidy up `make_request` (#188)
2024

2125
## 2.8.0 (2023-07-21)
2226

src/databricks/sql/auth/retry.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class DatabricksRetryPolicy(Retry):
5656
`backoff_factor`.
5757
5858
:param delay_max:
59-
Float of seconds for the maximum delay between retries. This is an alias for urllib3's
60-
`backoff_max`
59+
Float of seconds for the maximum delay between retries.
6160
6261
:param stop_after_attempts_count:
6362
Integer maximum number of attempts that will be retried. This is an alias for urllib3's
@@ -122,7 +121,6 @@ def __init__(
122121
total=_attempts_remaining,
123122
respect_retry_after_header=True,
124123
backoff_factor=self.delay_min,
125-
backoff_max=self.delay_max,
126124
allowed_methods=["POST"],
127125
status_forcelist=[429, 503, *self.force_dangerous_codes],
128126
)
@@ -212,13 +210,11 @@ def new(self, **urllib3_incremented_counters: typing.Any) -> Retry:
212210
allowed_methods=self.allowed_methods,
213211
status_forcelist=self.status_forcelist,
214212
backoff_factor=self.backoff_factor, # type: ignore
215-
backoff_max=self.backoff_max, # type: ignore
216213
raise_on_redirect=self.raise_on_redirect,
217214
raise_on_status=self.raise_on_status,
218215
history=self.history,
219216
remove_headers_on_redirect=self.remove_headers_on_redirect,
220217
respect_retry_after_header=self.respect_retry_after_header,
221-
backoff_jitter=self.backoff_jitter, # type: ignore
222218
)
223219

224220
# Update urllib3's current state to reflect the incremented counters

tests/e2e/common/retry_test_mixins.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ def _test_retry_disabled_with_message(self, error_msg_substring, exception_type)
5858

5959

6060
@contextmanager
61-
def mocked_server_response(status: int = 200, headers: dict = {"Retry-After": None}):
61+
def mocked_server_response(status: int = 200, headers: dict = {}):
6262
"""Context manager for patching urllib3 responses"""
6363

6464
# When mocking mocking a BaseHTTPResponse for urllib3 the mock must include
6565
# 1. A status code
6666
# 2. A headers dict
6767
# 3. mock.get_redirect_location() return falsy
68-
mock_response = MagicMock(headers=headers, status=status)
68+
69+
# `msg` is included for testing when urllib3~=1.0.0 is installed
70+
mock_response = MagicMock(headers=headers, msg=headers, status=status)
6971
mock_response.get_redirect_location.return_value = False
7072

7173
with patch("urllib3.connectionpool.HTTPSConnectionPool._get_conn") as getconn_mock:
@@ -91,7 +93,9 @@ def mock_sequential_server_responses(responses: List[dict]):
9193
# Each resp should have these members:
9294

9395
for resp in responses:
94-
_mock = MagicMock(headers=resp["headers"], status=resp["status"])
96+
_mock = MagicMock(
97+
headers=resp["headers"], msg=resp["headers"], status=resp["status"]
98+
)
9599
_mock.get_redirect_location.return_value = False
96100
mock_responses.append(_mock)
97101

@@ -239,7 +243,7 @@ def test_retry_safe_execute_statement_retry_condition(self):
239243

240244
responses = [
241245
{"status": 429, "headers": {"Retry-After": "1"}},
242-
{"status": 503, "headers": {"Retry-After": None}},
246+
{"status": 503, "headers": {}},
243247
]
244248

245249
with self.connection(
@@ -262,7 +266,7 @@ def test_retry_abort_close_session_on_404(self):
262266
# Second response is a 404 because the session is no longer found
263267
responses = [
264268
{"status": 502, "headers": {"Retry-After": "1"}},
265-
{"status": 404, "headers": {"Retry-After": None}},
269+
{"status": 404, "headers": {}},
266270
]
267271

268272
with self.connection(extra_params={**self._retry_policy}) as conn:
@@ -292,7 +296,7 @@ def test_retry_abort_close_operation_on_404(self):
292296
# Second response is a 404 because the session is no longer found
293297
responses = [
294298
{"status": 502, "headers": {"Retry-After": "1"}},
295-
{"status": 404, "headers": {"Retry-After": None}},
299+
{"status": 404, "headers": {}},
296300
]
297301

298302
with self.connection(extra_params={**self._retry_policy}) as conn:

0 commit comments

Comments
 (0)