{"record":{"id":"047bc94728871f1c","repo":"locustio/locust","slug":"unrecognized-task-type-in-user","errorCode":null,"errorMessage":"Unrecognized task type in user","messagePattern":"Unrecognized task type in user","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"locust/env.py","lineNumber":287,"sourceCode":"\n    def assign_equal_weights(self) -> None:\n        \"\"\"\n        Update the user classes such that each user runs their specified tasks with equal\n        probability.\n        \"\"\"\n        for u in self.user_classes:\n            u.weight = 1\n            user_tasks: list[TaskSet | Callable] = []\n            tasks_frontier = u.tasks\n            while len(tasks_frontier) != 0:\n                t = tasks_frontier.pop()\n                if isinstance(t, TaskHolder):\n                    tasks_frontier.extend(t.tasks)\n                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","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/env.py#L269-L305","documentation":"When assign_equal_weights() flattens a user's task set, each entry must be either a TaskHolder (e.g. TaskSet/nested class) or a callable (@task method). Anything else is invalid and raises ValueError.","triggerScenarios":"Putting a non-callable, non-TaskHolder object in a user's `tasks` list, e.g. a class instance, string, or a plain attribute reference that isn't a function.","commonSituations":"Appending tasks programmatically and pushing the wrong object; typos like `tasks = [my_task()]` (instance instead of function); mixing old-style task tuples incorrectly.","solutions":["Ensure every item in `tasks` is either a callable decorated with @task or a TaskSet/TaskHolder subclass","Remove or fix entries that are instances, strings, or other objects","Use the @task decorator instead of manual list manipulation"],"exampleFix":"// before\nMyUser.tasks = [\"do_thing\"]\n// after\nMyUser.tasks = [do_thing]  # do_thing is a @task-decorated callable or TaskSet subclass","handlingStrategy":"type-guard","validationCode":"from locust.exception import StopUser\n\ndef valid_tasks(user_cls) -> bool:\n    from locust import TaskSet\n    return all(callable(t) or (isinstance(t, type) and issubclass(t, TaskSet)) for t in user_cls.tasks)","typeGuard":"def is_valid_task(t) -> bool:\n    from locust import TaskSet\n    return callable(t) or (isinstance(t, type) and issubclass(t, TaskSet))","tryCatchPattern":"try:\n    env.assign_equal_weights()\nexcept ValueError as e:\n    if \"Unrecognized task type\" in str(e):\n        raise RuntimeError(\"Fix tasks list: use @task callables or TaskSet subclasses\") from e\n    raise","preventionTips":["Only put @task callables or TaskSet subclasses in `tasks`","Don't instantiate tasks in the list (`[MyTaskSet]`, not `[MyTaskSet()]`)","Type-check task lists with the guard above in tests"],"tags":["tasks","users","validation"],"backgroundTag":"invalid-task-definition","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}