Skip to content

Commit

Permalink
Limit milvus-lite files to end with .db
Browse files Browse the repository at this point in the history
Signed-off-by: junjie.jiang <[email protected]>
  • Loading branch information
junjiejiangjjj committed Aug 5, 2024
1 parent 5bf0a24 commit d842e9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pymilvus/orm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ def add_connection(self, **kwargs):
self._alias[alias] = alias_config

def __get_full_address(
self,
address: str = "",
uri: str = "",
host: str = "",
port: str = "",
self, address: str = "", uri: str = "", host: str = "", port: str = "",
) -> (str, parse.ParseResult):
if address != "":
if not is_legal_address(address):
Expand Down Expand Up @@ -365,10 +361,11 @@ def connect(
"tcp",
]:
# start and connect milvuslite
if kwargs["uri"].endswith("/"):
if not kwargs["uri"].endswith(".db"):
raise ConnectionConfigException(
message=f"Open local milvus failed, {kwargs['uri']} is not a local file path"
message=f"Open local milvus failed, {kwargs['uri']} is not endswith .db"
)

parent_path = pathlib.Path(kwargs["uri"]).parent
if not parent_path.is_dir():
raise ConnectionConfigException(
Expand All @@ -377,6 +374,7 @@ def connect(

from milvus_lite.server_manager import server_manager_instance

logger.info(f"Pass in the local path {kwargs['uri']}, and run it using milvus-lite")
local_uri = server_manager_instance.start_and_get_uri(kwargs["uri"])
if local_uri is None:
raise ConnectionConfigException(message="Open local milvus failed")
Expand Down
8 changes: 8 additions & 0 deletions tests/test_milvus_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pymilvus.milvus_client import MilvusClient
from pymilvus.exceptions import ConnectionConfigException


@pytest.mark.skipif(sys.platform.startswith('win'), reason="Milvus Lite is not supported on Windows")
Expand Down Expand Up @@ -56,3 +57,10 @@ def test_milvus_lite(self):
filter="subject == 'history'",
)
assert len(res) == 3

def test_illegal_name(self):
try:
MilvusClient("localhost")
assert False
except ConnectionConfigException as e:
assert e.message == "Open local milvus failed, localhost is not endswith .db"

0 comments on commit d842e9a

Please sign in to comment.