locustio/locust · error · ValueError

'collection_name' must be provided for MilvusUser

Error message

'collection_name' must be provided for MilvusUser

What it means

MilvusUser.__init__ raises ValueError when collection_name is None because both the pymilvus client operations and the benchmark logic need a target collection. It fails fast before constructing the MilvusV2Client.

Source

Thrown at locust/contrib/milvus.py:310

    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))
        events.request.fire(
            request_type=f"{request_type}",

View on GitHub (pinned to f391a716e1)

Solutions

  1. Pass collection_name=... to MilvusUser.__init__
  2. Load the collection name from an environment variable or config file
  3. Verify your subclass forwards the argument to super().__init__

Example fix

// before
super().__init__(environment, uri=uri)
// after
super().__init__(environment, uri=uri, collection_name=os.environ["MILVUS_COLLECTION"])
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Instantiating MilvusUser without collection_name=..., or with collection_name explicitly None.

Common situations: Custom User subclasses not forwarding collection_name; collection created outside the locustfile and its name not wired into the test config; copy-pasted locustfile missing the parameter.

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/48d677631673c916. Report an issue: GitHub.