Skip to content

Commit 918752f

Browse files
NodeJSmithJesse Whitehouse
and
Jesse Whitehouse
authored
Fix URI construction in ThriftBackend (databricks#303)
Signed-off-by: Jessica <[email protected]> Signed-off-by: Jesse Whitehouse <[email protected]> Co-authored-by: Jesse Whitehouse <[email protected]>
1 parent 3f6834c commit 918752f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
# 3.1.0 (TBD)
4+
5+
- Fix: `server_hostname` URIs that included `https://` would raise an exception
6+
37
## 3.0.1 (2023-12-01)
48

59
- Other: updated docstring comment about default parameterization approach (#287)

src/databricks/sql/thrift_backend.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ def __init__(
141141
if kwargs.get("_connection_uri"):
142142
uri = kwargs.get("_connection_uri")
143143
elif server_hostname and http_path:
144-
uri = "https://{host}:{port}/{path}".format(
145-
host=server_hostname, port=port, path=http_path.lstrip("/")
144+
uri = "{host}:{port}/{path}".format(
145+
host=server_hostname.rstrip("/"), port=port, path=http_path.lstrip("/")
146146
)
147+
if not uri.startswith("https://"):
148+
uri = "https://" + uri
147149
else:
148150
raise ValueError("No valid connection settings.")
149151

tests/unit/test_thrift_backend.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ def test_port_and_host_are_respected(self, t_http_client_class):
212212
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
213213
"https://hostname:123/path_value")
214214

215+
@patch("databricks.sql.auth.thrift_http_client.THttpClient")
216+
def test_host_with_https_does_not_duplicate(self, t_http_client_class):
217+
ThriftBackend("https://hostname", 123, "path_value", [], auth_provider=AuthProvider())
218+
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
219+
"https://hostname:123/path_value")
220+
221+
@patch("databricks.sql.auth.thrift_http_client.THttpClient")
222+
def test_host_with_trailing_backslash_does_not_duplicate(self, t_http_client_class):
223+
ThriftBackend("https://hostname/", 123, "path_value", [], auth_provider=AuthProvider())
224+
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
225+
"https://hostname:123/path_value")
226+
215227
@patch("databricks.sql.auth.thrift_http_client.THttpClient")
216228
def test_socket_timeout_is_propagated(self, t_http_client_class):
217229
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=129)

0 commit comments

Comments
 (0)