Skip to content

Commit e941adb

Browse files
fix: [cp25]db_name overwritten by empty string (#2678) (#2702)
issue: #2670 pr: #2678 Added a unit test for it as well. Signed-off-by: yangxuan <xuan.yang@zilliz.com> Co-authored-by: Mihail Yanchev <34907806+mihailyanchev@users.noreply.github.com> Co-authored-by: Mihail Yanchev <yanchev.mihail@gmail.com>
1 parent 9969ac0 commit e941adb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pymilvus/orm/connections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def with_config(config: Tuple) -> bool:
451451
user = parsed_uri.username or user
452452
password = parsed_uri.password or password
453453

454-
group = parsed_uri.path.split("/")
454+
group = [segment for segment in parsed_uri.path.split("/") if segment]
455455
db_name = group[1] if len(group) > 1 else db_name
456456

457457
# Set secure=True if https scheme

tests/test_connections.py

+25
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,28 @@ def test_issue_1196(self):
372372

373373
config = connections.get_connection_addr("default")
374374
assert config == {"address": 'localhost:19531', "user": 'root', "secure": True}
375+
376+
def test_issue_2670(self):
377+
"""
378+
Test for db_name being overwritten with empty string, when the uri
379+
ends in a slash - e.g. http://localhost:19530/
380+
381+
See: https://github.com/milvus-io/pymilvus/issues/2670
382+
383+
Actual behaviour before fix: if a uri is passed ending with a slash,
384+
it will overwrite the db_name with an empty string.
385+
Expected and current behaviour: if db_name is passed explicitly,
386+
it should be used in the initialization of the GrpcHandler.
387+
388+
"""
389+
db_name = "default"
390+
alias = self.test_issue_2670.__name__
391+
392+
with mock.patch(f"{mock_prefix}.__init__", return_value=None) as mock_init, mock.patch(
393+
f"{mock_prefix}._wait_for_channel_ready", return_value=None):
394+
config = {"alias": alias, "uri": "http://localhost:19530/", "db_name": db_name}
395+
connections.connect(**config)
396+
397+
mock_init.assert_called_with(
398+
**{'address': 'localhost:19530', 'user': '', 'password': '', 'token': '', 'db_name': db_name}
399+
)

0 commit comments

Comments
 (0)