diff --git a/pymilvus/orm/connections.py b/pymilvus/orm/connections.py index 8941ed66c..0cd954440 100644 --- a/pymilvus/orm/connections.py +++ b/pymilvus/orm/connections.py @@ -233,7 +233,6 @@ def connect_milvus(**kwargs): and connection_details["address"] == kwargs["address"] and connection_details["user"] == kwargs["user"] and connection_details["db_name"] == kwargs["db_name"] - ): gh = self._connected_alias[key] break @@ -267,9 +266,8 @@ def connect_milvus(**kwargs): password = '' if password is None else str(password) db_name = '' if db_name is None else str(db_name) - address, user, password, db_name = self.__parse_info(address, uri, host, port, db_name, user, password) - - if set([address, uri, host, port]) != {None}: + if set([address, uri, host, port]) != {''}: + address, user, password, db_name = self.__parse_info(address, uri, host, port, db_name, user, password) kwargs["address"] = address elif alias in self._alias: @@ -362,13 +360,14 @@ def __parse_info( db_name: str = "", user: str = "", password: str = "", - ) -> dict: + **kwargs) -> dict: passed_in_address = "" passed_in_user = "" passed_in_password = "" passed_in_db_name = "" + # If uri if uri != "": passed_in_address, passed_in_user, passed_in_password, passed_in_db_name = ( self.__parse_address_from_uri(uri) @@ -429,11 +428,13 @@ def __parse_address_from_uri(self, uri: str) -> Tuple[str, str, str, str]: user = parsed_uri.username if parsed_uri.username is not None else "" password = parsed_uri.password if parsed_uri.password is not None else "" - if host != "" and port != "": - self.__verify_host_port(host, port) - addr = f"{host}:{port}" - else: - addr = "" + if host == "": + raise ConnectionConfigException(message="Illegal uri: URI is missing host address: {}".format(uri)) + if port == "": + raise ConnectionConfigException(message="Illegal uri: URI is missing port: {}".format(uri)) + + self.__verify_host_port(host, port) + addr = f"{host}:{port}" if not is_legal_address(addr): raise ConnectionConfigException(message=illegal_uri_msg.format(uri)) diff --git a/tests/test_connections.py b/tests/test_connections.py index 0adcd75ee..8a0b6ec47 100644 --- a/tests/test_connections.py +++ b/tests/test_connections.py @@ -328,7 +328,6 @@ def test_add_connection_address_invalid(self, invalid_addr): {"uri": "http://127.0.0.1:19530"}, {"uri": "http://localhost:19530"}, {"uri": "http://example.com:80"}, - {"uri": "http://example.com"}, ]) def test_add_connection_uri(self, valid_uri): alias = self.test_add_connection_uri.__name__ @@ -350,6 +349,8 @@ def test_add_connection_uri(self, valid_uri): {"uri": "http://"}, {"uri": None}, {"uri": -1}, + {"uri": "http://example.com"}, + {"uri": "http://:90"}, ]) def test_add_connection_uri_invalid(self, invalid_uri): alias = self.test_add_connection_uri_invalid.__name__