Skip to content

Commit 22df3e5

Browse files
committed
Fix
Signed-off-by: Mihail Yanchev <yanchev.mihail@gmail.com>
1 parent e0d5cf7 commit 22df3e5

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

pymilvus/orm/connections.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ def with_config(config: Tuple) -> bool:
454454
user = parsed_uri.username or user
455455
password = parsed_uri.password or password
456456

457-
group = [segment for segment in parsed_uri.path.split("/") if segment]
458-
db_name = group[1] if len(group) > 1 else db_name
457+
db_name = parsed_uri.path.lstrip("/").split("/", 1)[0] or db_name
459458

460459
# Set secure=True if https scheme
461460
if parsed_uri.scheme == "https":

tests/test_connections.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,11 @@ def test_issue_1196(self):
373373
config = connections.get_connection_addr("default")
374374
assert config == {"address": 'localhost:19531', "user": 'root', "secure": True}
375375

376-
def test_issue_2670(self):
376+
@pytest.mark.parametrize("uri, db_name", [("http://localhost:19530", "test_db"), ("http://localhost:19530/", "test_db"), ("http://localhost:19530/test_db", None)])
377+
def test_issue_2670_2727(self, uri: str, db_name: str | None):
377378
"""
379+
Issue 2670:
380+
378381
Test for db_name being overwritten with empty string, when the uri
379382
ends in a slash - e.g. http://localhost:19530/
380383
@@ -384,16 +387,28 @@ def test_issue_2670(self):
384387
it will overwrite the db_name with an empty string.
385388
Expected and current behaviour: if db_name is passed explicitly,
386389
it should be used in the initialization of the GrpcHandler.
390+
391+
Issue 2727:
392+
If db_name is passed as a path to the uri and not explicitly passed as an argument,
393+
it is not overwritten with an empty string.
394+
395+
See: https://github.com/milvus-io/pymilvus/issues/2727
396+
397+
Actual behaviour before fix: if db_name is passed as a path to the uri,
398+
it will overwrite the db_name with an empty string.
399+
Expected and current behaviour: if db_name is passed as a path to the uri,
400+
it should be used in the initialization of the GrpcHandler.
387401
388402
"""
389-
db_name = "default"
390-
alias = self.test_issue_2670.__name__
403+
alias = self.test_issue_2670_2727.__name__
391404

392405
with mock.patch(f"{mock_prefix}.__init__", return_value=None) as mock_init, mock.patch(
393406
f"{mock_prefix}._wait_for_channel_ready", return_value=None):
394-
config = {"alias": alias, "uri": "http://localhost:19530/", "db_name": db_name}
407+
config = {"alias": alias, "uri": uri, "db_name": db_name}
395408
connections.connect(**config)
396409

410+
db_name = db_name or uri.split("/")[-1]
411+
397412
mock_init.assert_called_with(
398413
**{'address': 'localhost:19530', 'user': '', 'password': '', 'token': '', 'db_name': db_name}
399414
)

0 commit comments

Comments
 (0)