{"record":{"id":"dda89aeacbe778bc","repo":"locustio/locust","slug":"usage-of-user-task-set-is-deprecated-since-version","errorCode":null,"errorMessage":"Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead (tasks = [{task_set.__name__}])","messagePattern":"Usage of User\\.task_set is deprecated since version 1\\.0\\. Set the tasks attribute instead \\(tasks = \\[(.+?)\\]\\)","errorType":"console","errorClass":"DeprecationWarning","httpStatus":null,"severity":"warning","filePath":"locust/util/deprecation.py","lineNumber":13,"sourceCode":"import warnings\n\n# Show deprecation warnings\nwarnings.filterwarnings(\"always\", category=DeprecationWarning, module=\"locust\")\n\n\ndef check_for_deprecated_task_set_attribute(class_dict):\n    from locust.user.task import TaskSet\n\n    if \"task_set\" in class_dict:\n        task_set = class_dict[\"task_set\"]\n        if issubclass(task_set, TaskSet) and not hasattr(task_set, \"locust_task_weight\"):\n            warnings.warn(\n                \"Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead \"\n                f\"(tasks = [{task_set.__name__}])\",\n                DeprecationWarning,\n            )\n\n\ndef deprecated_locust_meta_class(deprecation_message):\n    class MetaClass(type):\n        def __new__(mcs, classname, bases, class_dict):\n            if classname in [\"DeprecatedLocustClass\", \"DeprecatedHttpLocustClass\", \"DeprecatedFastHttpLocustClass\"]:\n                return super().__new__(mcs, classname, bases, class_dict)\n            else:\n                raise ImportError(deprecation_message)\n\n    return MetaClass\n\n\n# PEP 484 specifies \"Generic metaclasses are not supported\", see https://github.com/python/mypy/issues/3602, ignore typing errors","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/util/deprecation.py#L1-L31","documentation":"check_for_deprecated_task_set_attribute emits a DeprecationWarning when a User class dict contains a `task_set` attribute set to a TaskSet subclass — the pre-1.0 API. It still warns (does not raise) telling users to use `tasks` instead.","triggerScenarios":"Defining a User class with `task_set = SomeTaskSet` (singular) rather than `tasks = [SomeTaskSet]`, where the TaskSet has no locust_task_weight.","commonSituations":"Migrating locustfiles from Locust 0.x to 1.0+; old documentation examples using task_set.","solutions":["Replace `task_set = MyTaskSet` with `tasks = [MyTaskSet]`","Add @task(weight) weighting if different task sets need different frequencies","Run with -W error::DeprecationWarning in CI to catch old patterns"],"exampleFix":"// before\nclass MyUser(User):\n    task_set = MyTaskSet\n// after\nclass MyUser(User):\n    tasks = [MyTaskSet]","handlingStrategy":"validation","validationCode":"assert 'task_set' not in vars(MyUser), \"Use tasks = [MyTaskSet] instead of task_set\"","typeGuard":null,"tryCatchPattern":"import warnings\nwith warnings.catch_warnings(record=True) as w:\n    warnings.simplefilter(\"always\")\n    # import locustfile\n    assert not any(issubclass(x.category, DeprecationWarning) for x in w)","preventionTips":["Use `tasks` list attribute exclusively","Enable DeprecationWarning filters in CI"],"tags":["python","locust","deprecation","migration"],"backgroundTag":"deprecated-task-set-attribute","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}