pymilvus icon indicating copy to clipboard operation
pymilvus copied to clipboard

[Bug]: db_name should return when list_connections called

Open hasansustcse13 opened this issue 8 months ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I have a requirement where I need to connect to different db on same address (host + port) at the same time. And I have to use existing connection if it's alive for this is the code has been written (basically written in langchain codebase)

  if given_address is not None:
            for con in connections.list_connections():
                addr = connections.get_connection_addr(con[0])
                if (
                    con[1]
                    and ("address" in addr)
                    and (addr["address"] == given_address)
                    and ("user" in addr)
                    and (addr["user"] == tmp_user)
                ):
                    logger.debug("Using previous connection: %s", con[0])
                    return con[0]

        # Generate a new connection if one doesn't exist
        alias = uuid4().hex
        try:
            connections.connect(alias=alias, **connection_args)
            logger.debug("Created new connection using: %s", alias)
            return alias
        except MilvusException as e:
            logger.error("Failed to create new connection using: %s", alias)
            raise e

Let's say collection_1 is connected to db_1 and Now I want collection_2 will be connect to db_2. As addr = connections.get_connection_addr(con[0]) don't have the db_name value the if block will be executed and provide db_1 connection which is wrong.

I believe this is single line fix when connect to milvus we should store the db_name instead of popping. Code from Milvus:

def connect_milvus(**kwargs):
            # rest of the code
            kwargs.pop("password")
            kwargs.pop("token", None)
            kwargs.pop("db_name", "")  # the bug

            self._connected_alias[alias] = gh
            self._alias[alias] = copy.deepcopy(kwargs)

Expected Behavior

No response

Steps/Code To Reproduce behavior

No response

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

hasansustcse13 avatar Jul 02 '24 04:07 hasansustcse13