Skip to content

Commit 4608817

Browse files
committed
refactor(connection, client-protocol): log when there is a mismatch in requested vs granted protocol
1 parent 02ade3a commit 4608817

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

redshift_connector/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import socket
34
import typing
@@ -115,6 +116,7 @@
115116

116117
__author__ = "Mathieu Fenniak"
117118

119+
_logger: logging.Logger = logging.getLogger(__name__)
118120

119121
ZERO: Timedelta = Timedelta(0)
120122
BINARY: type = bytes
@@ -1364,12 +1366,11 @@ def handle_PARAMETER_STATUS(self: "Connection", data: bytes, ps) -> None:
13641366
# when a mismatch occurs between the client's requested protocol version, and the server's response,
13651367
# warn the user and follow server
13661368
if self._client_protocol_version != int(value):
1367-
warn(
1369+
_logger.debug(
13681370
"Server indicated {} transfer protocol will be used rather than protocol requested by client: {}".format(
13691371
ClientProtocolVersion.get_name(int(value)),
13701372
ClientProtocolVersion.get_name(self._client_protocol_version),
1371-
),
1372-
stacklevel=3,
1373+
)
13731374
)
13741375
self._client_protocol_version = int(value)
13751376
elif key == b"server_version":

test/integration/test_connection.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import configparser
2+
import logging
23
import os
34
import random
45
import socket
@@ -16,6 +17,8 @@
1617
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1718
conf.read(root_path + "/config.ini")
1819

20+
logger = logging.getLogger(__name__)
21+
1922
# Check if running in Jython
2023
if "java" in sys.platform:
2124
from jarray import array # type: ignore
@@ -195,12 +198,17 @@ def test_client_protocol_version_is_used(db_kwargs, _input):
195198
assert conn._client_protocol_version == _input
196199

197200

198-
def test_client_protocol_version_invalid_warns_user(db_kwargs):
201+
def test_client_protocol_version_invalid_logs(db_kwargs, caplog):
199202
db_kwargs["client_protocol_version"] = max(ClientProtocolVersion.list()) + 1
200203
del db_kwargs["region"]
201204
del db_kwargs["cluster_identifier"]
202-
with pytest.warns(UserWarning):
203-
redshift_connector.Connection(**db_kwargs)
205+
206+
with caplog.at_level(logging.DEBUG):
207+
with redshift_connector.Connection(**db_kwargs) as con:
208+
act_client_protocol: int = con._client_protocol_version
209+
assert "Server indicated {} transfer protocol will be used rather than protocol requested by client: {}".format(
210+
act_client_protocol, db_kwargs["client_protocol_version"]
211+
)
204212

205213

206214
def test_stl_connection_log_contains_driver_version(db_kwargs):

0 commit comments

Comments
 (0)