Skip to content

Commit af01fdf

Browse files
authored
do not override port if defined in host (#362)
## Problem For an Index gRPC connection, port 443 is blindly added to the configured host for setting up the endpoint. A user should be able to specify a port for connection. ## Solution This PR will no longer append ":443" to the configured gRPC endpoint if a colon is already present in the host configuration. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Unit tests were updated for omitting and including a port in the host config. Verified that the client could connect to an Index on a port other than 443.
1 parent ab3ccfe commit af01fdf

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pinecone/grpc/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ def stub_class(self):
8484
pass
8585

8686
def _endpoint(self):
87-
grpcHost = self.config.host.replace("https://", "")
88-
return self._endpoint_override if self._endpoint_override else f"{grpcHost}:443"
87+
grpc_host = self.config.host.replace("https://", "")
88+
if ":" not in grpc_host:
89+
grpc_host = f"{grpc_host}:443"
90+
return self._endpoint_override if self._endpoint_override else grpc_host
8991

9092
def _gen_channel(self, options=None):
9193
target = self._endpoint()

tests/unit_grpc/test_grpc_index_initialization.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ def test_config_passed_when_target_by_host(self):
8585
assert index.grpc_client_config.reuse_channel == True
8686
assert index.grpc_client_config.conn_timeout == 1
8787

88+
# Endpoint port defaults to 443
89+
assert index._endpoint() == "myhost:443"
90+
91+
def test_config_passed_when_target_by_host_and_port(self):
92+
pc = PineconeGRPC(api_key="YOUR_API_KEY")
93+
config = GRPCClientConfig(timeout=5, secure=False)
94+
index = pc.Index(host="myhost:4343", grpc_config=config)
95+
96+
assert index.grpc_client_config.timeout == 5
97+
assert index.grpc_client_config.secure == False
98+
99+
# Unset fields still get default values
100+
assert index.grpc_client_config.reuse_channel == True
101+
assert index.grpc_client_config.conn_timeout == 1
102+
103+
# Endpoint calculation does not override port
104+
assert index._endpoint() == "myhost:4343"
105+
88106
def test_config_passes_source_tag_when_set(self):
89107
pc = PineconeGRPC(api_key="YOUR_API_KEY", source_tag="my_source_tag")
90108
index = pc.Index(name="my-index", host="host")

0 commit comments

Comments
 (0)