{"record":{"id":"d22842b261ad9231","repo":"locustio/locust","slug":"shape-class-should-be-instance-of-loadtestshape-or","errorCode":null,"errorMessage":"shape_class should be instance of LoadTestShape or subclass LoadTestShape, but got: {self.shape_class}","messagePattern":"shape_class should be instance of LoadTestShape or subclass LoadTestShape, but got: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"locust/env.py","lineNumber":301,"sourceCode":"                elif callable(t):\n                    if t not in user_tasks:\n                        user_tasks.append(t)\n                else:\n                    raise ValueError(\"Unrecognized task type in user\")\n            u.tasks = user_tasks\n\n    def _validate_user_class_name_uniqueness(self):\n        # Validate there's no class with the same name but in different modules\n        if len({user_class.__name__ for user_class in self.user_classes}) != len(self.user_classes):\n            raise ValueError(\n                \"The following user classes have the same class name: {}\".format(\n                    \", \".join(map(methodcaller(\"fullname\"), self.user_classes))\n                )\n            )\n\n    def _validate_shape_class_instance(self):\n        if self.shape_class is not None and not isinstance(self.shape_class, LoadTestShape):\n            raise ValueError(\n                f\"shape_class should be instance of LoadTestShape or subclass LoadTestShape, but got: {self.shape_class}\"\n            )\n\n    @property\n    def user_classes_by_name(self) -> dict[str, type[User]]:\n        return {u.__name__: u for u in self.user_classes}\n","sourceCodeStart":283,"sourceCodeEnd":308,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/env.py#L283-L308","documentation":"Environment.shape_class must be an instance of LoadTestShape (not a class). If a non-None value is passed that is not a LoadTestShape instance, this ValueError is raised.","triggerScenarios":"Passing the LoadTestShape subclass itself (e.g. `shape_class=MyShape`) instead of an instance (`shape_class=MyShape()`); passing a completely unrelated object.","commonSituations":"Confusion between classes and instances when wiring a load shape in scripts or tests; refactors that pass the class after previously instantiating it.","solutions":["Instantiate the shape class: `Environment(..., shape_class=MyShape())`","Verify the object passed derives from locust.shape.LoadTestShape","Fix references that pass the class object instead of an instance"],"exampleFix":"// before\nenv = Environment(user_classes=[MyUser], shape_class=MyShape)\n// after\nenv = Environment(user_classes=[MyUser], shape_class=MyShape())","handlingStrategy":"type-guard","validationCode":"from locust import LoadTestShape\n\nshape = MyShape()\nassert isinstance(shape, LoadTestShape), \"shape_class must be a LoadTestShape instance\"\nenv = Environment(user_classes=[MyUser], shape_class=shape)","typeGuard":"from locust import LoadTestShape\n\ndef is_valid_shape(shape) -> bool:\n    return isinstance(shape, LoadTestShape)","tryCatchPattern":"try:\n    env = Environment(user_classes=[MyUser], shape_class=MyShape())\nexcept ValueError as e:\n    if \"shape_class\" in str(e):\n        raise RuntimeError(\"Pass an instance: shape_class=MyShape()\") from e\n    raise","preventionTips":["Always instantiate: `shape_class=MyShape()` not `MyShape`","Keep imports from locust.shape / locust import LoadTestShape consistent","Test Environment construction in CI"],"tags":["load-shape","configuration","type-validation"],"backgroundTag":"wrong-type-argument","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}