locustio/locust · error · ValueError

'uri' must be provided for MilvusUser

Error message

'uri' must be provided for MilvusUser

What it means

MilvusUser.__init__ requires a Milvus server URI and raises ValueError immediately when uri is None, since the underlying pymilvus MilvusV2Client cannot connect without it. This fail-fast validation happens before any network activity.

Source

Thrown at locust/contrib/milvus.py:308

    abstract = True

    def __init__(
        self,
        environment,
        uri: str = "http://localhost:19530",
        token: str = "root:Milvus",
        collection_name: str = "test_collection",
        db_name: str = "default",
        timeout: int = 60,
        schema: CollectionSchema | None = None,
        index_params: IndexParams | None = None,
        **kwargs,  # enable_dynamic_field, num_shards, consistency_level etc. ref: https://milvus.io/api-reference/pymilvus/v2.6.x/MilvusClient/Collections/create_collection.md
    ):
        super().__init__(environment)

        if uri is None:
            raise ValueError("'uri' must be provided for MilvusUser")
        if collection_name is None:
            raise ValueError("'collection_name' must be provided for MilvusUser")

        self.client_type = "milvus"
        self.client = MilvusV2Client(
            uri=uri,
            token=token,
            collection_name=collection_name,
            db_name=db_name,
            timeout=timeout,
        )
        if schema is not None:
            self.client.create_collection(schema=schema, index_params=index_params, **kwargs)

    @staticmethod
    def _fire_event(request_type: str, name: str, result: dict[str, Any]):
        """Emit a Locust request event from a Milvus client result dict."""
        response_time = int(result.get("response_time", 0))

View on GitHub (pinned to f391a716e1)

Solutions

  1. Pass uri=... to MilvusUser.__init__ (e.g. http://localhost:19530)
  2. Load the URI from an environment variable and pass it through
  3. Check that your custom User subclass forwards **kwargs/uri to super().__init__

Example fix

// before
class MilvusLoadUser(MilvusUser):
    def __init__(self, environment):
        super().__init__(environment)
// after
class MilvusLoadUser(MilvusUser):
    def __init__(self, environment):
        super().__init__(environment, uri=os.environ["MILVUS_URI"], collection_name="demo")
Defensive patterns

Strategy: validation

Validate before calling

import os
uri = os.environ.get("MILVUS_URI")
assert uri, "MILVUS_URI env var must be set for MilvusUser"
# then: super().__init__(environment, uri=uri, collection_name=...)

Prevention

When it happens

Trigger: Instantiating MilvusUser (directly or as a base class of a custom user) without passing uri=..., or with uri explicitly None.

Common situations: Subclassing MilvusUser and overriding __init__ without forwarding uri; forgetting to load the URI from an environment variable or config; running the locustfile with missing CLI/config values.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/50b4185c0a42a14e. Report an issue: GitHub.