Skip to content

Commit 416ff57

Browse files
authored
SNOW-1571763 fix login timeout read pattern (#2022)
1 parent 7b596b2 commit 416ff57

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1111
- v3.12.1(TBD)
1212
- Fixed a bug that session token is logged when renewing session.
1313
- Fixed a bug that disabling client telemetry does not work.
14+
- Fixed a bug where `login_timeout` when passed as string raised `TypeError` during login retry step.
1415
- Use `pathlib` instead of `os` for default config file location resolution.
1516
- Removed upper `cryptogaphy` version pin.
1617
- Removed reference to script `snowflake-export-certs` (its backing module was already removed long ago)

src/snowflake/connector/auth/_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def authenticate(
198198
self._rest._connection._internal_application_name,
199199
self._rest._connection._internal_application_version,
200200
self._rest._connection._ocsp_mode(),
201-
self._rest._connection._login_timeout,
201+
self._rest._connection.login_timeout,
202202
self._rest._connection._network_timeout,
203203
self._rest._connection._socket_timeout,
204204
)

src/snowflake/connector/auth/okta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _step1(
170170
conn._internal_application_name,
171171
conn._internal_application_version,
172172
conn._ocsp_mode(),
173-
conn._login_timeout,
173+
conn.login_timeout,
174174
conn._network_timeout,
175175
)
176176

src/snowflake/connector/auth/webbrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def _get_sso_url(
462462
conn._rest._connection._internal_application_name,
463463
conn._rest._connection._internal_application_version,
464464
conn._rest._connection._ocsp_mode(),
465-
conn._rest._connection._login_timeout,
465+
conn._rest._connection.login_timeout,
466466
conn._rest._connection._network_timeout,
467467
)
468468

src/snowflake/connector/connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def __open_connection(self):
10181018
elif self._authenticator == DEFAULT_AUTHENTICATOR:
10191019
self.auth_class = AuthByDefault(
10201020
password=self._password,
1021-
timeout=self._login_timeout,
1021+
timeout=self.login_timeout,
10221022
backoff_generator=self._backoff_generator,
10231023
)
10241024
elif self._authenticator == EXTERNAL_BROWSER_AUTHENTICATOR:
@@ -1038,7 +1038,7 @@ def __open_connection(self):
10381038
protocol=self._protocol,
10391039
host=self.host,
10401040
port=self.port,
1041-
timeout=self._login_timeout,
1041+
timeout=self.login_timeout,
10421042
backoff_generator=self._backoff_generator,
10431043
)
10441044
else:
@@ -1048,7 +1048,7 @@ def __open_connection(self):
10481048
protocol=self._protocol,
10491049
host=self.host,
10501050
port=self.port,
1051-
timeout=self._login_timeout,
1051+
timeout=self.login_timeout,
10521052
backoff_generator=self._backoff_generator,
10531053
)
10541054

@@ -1063,13 +1063,13 @@ def __open_connection(self):
10631063

10641064
self.auth_class = AuthByKeyPair(
10651065
private_key=private_key,
1066-
timeout=self._login_timeout,
1066+
timeout=self.login_timeout,
10671067
backoff_generator=self._backoff_generator,
10681068
)
10691069
elif self._authenticator == OAUTH_AUTHENTICATOR:
10701070
self.auth_class = AuthByOAuth(
10711071
oauth_token=self._token,
1072-
timeout=self._login_timeout,
1072+
timeout=self.login_timeout,
10731073
backoff_generator=self._backoff_generator,
10741074
)
10751075
elif self._authenticator == USR_PWD_MFA_AUTHENTICATOR:
@@ -1085,14 +1085,14 @@ def __open_connection(self):
10851085
self.auth_class = AuthByUsrPwdMfa(
10861086
password=self._password,
10871087
mfa_token=self.rest.mfa_token,
1088-
timeout=self._login_timeout,
1088+
timeout=self.login_timeout,
10891089
backoff_generator=self._backoff_generator,
10901090
)
10911091
else:
10921092
# okta URL, e.g., https://<account>.okta.com/
10931093
self.auth_class = AuthByOkta(
10941094
application=self.application,
1095-
timeout=self._login_timeout,
1095+
timeout=self.login_timeout,
10961096
backoff_generator=self._backoff_generator,
10971097
)
10981098

test/integ/test_connection.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,25 @@ def test_bad_db(db_parameters):
279279
cnx.close()
280280

281281

282+
def test_with_string_login_timeout(db_parameters):
283+
"""Test that login_timeout when passed as string does not raise TypeError.
284+
285+
In this test, we pass bad login credentials to raise error and trigger login
286+
timeout calculation. We expect to see DatabaseError instead of TypeError that
287+
comes from str - int arithmetic.
288+
"""
289+
with pytest.raises(DatabaseError):
290+
snowflake.connector.connect(
291+
protocol="http",
292+
user="bogus",
293+
password="bogus",
294+
host=db_parameters["host"],
295+
port=db_parameters["port"],
296+
account=db_parameters["account"],
297+
login_timeout="5",
298+
)
299+
300+
282301
def test_bogus(db_parameters):
283302
"""Attempts to login with invalid user name and password.
284303

0 commit comments

Comments
 (0)