Skip to content

Commit ead14dd

Browse files
ai: apply changes for #876 (2 review threads)
Addresses: - #3636302124 at src/databricks/sql/auth/oauth.py:208 - #3636302135 at tests/unit/test_auth.py:240 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent bf48dae commit ead14dd

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/databricks/sql/auth/oauth.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,13 @@ def _on_timeout():
220220
# timeout. We do NOT fail fast merely on a falsy open_new return
221221
# value: that is unreliable across platforms (it can be falsy
222222
# even when a browser did open) and would break working
223-
# interactive logins. See issue #458. Placed before the generic
223+
# interactive logins. Note this fast-fail only covers the case
224+
# where webbrowser.get() raises; the more common headless case
225+
# (no browser registered, so open_new() returns False without
226+
# raising) is NOT caught here and instead falls through to the
227+
# bounded redirect-callback timeout below, which is the real
228+
# safeguard against blocking forever. See issue #458. Placed
229+
# before the generic
224230
# ``except Exception`` so this RuntimeError propagates instead of
225231
# being swallowed and retried against the remaining ports.
226232
msg = (

tests/unit/test_auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def test_get_tokens_does_not_hang_when_no_callback_received(
237237
client_id="mock-id",
238238
idp_endpoint=InHouseOAuthEndpointCollection(),
239239
http_client=MagicMock(),
240-
redirect_callback_timeout_seconds=2,
240+
# Sub-second so this real-wallclock wait stays negligible in the
241+
# fast/mocked unit suite. The wait IS the timeout, so there is no
242+
# setup racing against it that a shorter bound could make flaky.
243+
redirect_callback_timeout_seconds=0.5,
241244
)
242245

243246
# No callback is ever delivered to the redirect server. Run the flow in
@@ -325,7 +328,10 @@ def run_flow(port):
325328
client_id="mock-id",
326329
idp_endpoint=InHouseOAuthEndpointCollection(),
327330
http_client=MagicMock(),
328-
redirect_callback_timeout_seconds=2,
331+
# Sub-second: bounds the stalled request-line read. Keeps the
332+
# per-attempt wait negligible so even the rare TOCTOU retry loop
333+
# stays fast in the mocked unit suite.
334+
redirect_callback_timeout_seconds=0.5,
329335
)
330336

331337
result = {}

0 commit comments

Comments
 (0)