Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URI construction in ThriftBackend #303

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History

# 3.1.0 (TBD)

- Fix: `server_hostname` URIs that included `https://` would raise an exception

## 3.0.1 (2023-12-01)

- Other: updated docstring comment about default parameterization approach (#287)
Expand Down
6 changes: 4 additions & 2 deletions src/databricks/sql/thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ def __init__(
if kwargs.get("_connection_uri"):
uri = kwargs.get("_connection_uri")
elif server_hostname and http_path:
uri = "https://{host}:{port}/{path}".format(
host=server_hostname, port=port, path=http_path.lstrip("/")
uri = "{host}:{port}/{path}".format(
host=server_hostname.rstrip("/"), port=port, path=http_path.lstrip("/")
)
if not uri.startswith("https://"):
uri = "https://" + uri
else:
raise ValueError("No valid connection settings.")

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ def test_port_and_host_are_respected(self, t_http_client_class):
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
"https://hostname:123/path_value")

@patch("databricks.sql.auth.thrift_http_client.THttpClient")
def test_host_with_https_does_not_duplicate(self, t_http_client_class):
ThriftBackend("https://hostname", 123, "path_value", [], auth_provider=AuthProvider())
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
"https://hostname:123/path_value")

@patch("databricks.sql.auth.thrift_http_client.THttpClient")
def test_host_with_trailing_backslash_does_not_duplicate(self, t_http_client_class):
ThriftBackend("https://hostname/", 123, "path_value", [], auth_provider=AuthProvider())
self.assertEqual(t_http_client_class.call_args[1]["uri_or_host"],
"https://hostname:123/path_value")

@patch("databricks.sql.auth.thrift_http_client.THttpClient")
def test_socket_timeout_is_propagated(self, t_http_client_class):
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=129)
Expand Down
Loading