{"record":{"id":"6c0dc1bceb5e2b87","repo":"locustio/locust","slug":"taskset-run-is-a-method-used-internally-by-locus","errorCode":null,"errorMessage":"TaskSet.run() is a method used internally by Locust, and you must not override it or annotate it with transitions","messagePattern":"TaskSet\\.run\\(\\) is a method used internally by Locust, and you must not override it or annotate it with transitions","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"locust/user/markov_taskset.py","lineNumber":253,"sourceCode":"def validate_task_name(decorated_func):\n    \"\"\"\n    Validates that certain method names aren't used as Markov tasks.\n\n    This function checks for special method names that shouldn't be used as Markov tasks:\n    - \"on_stop\" and \"on_start\": Using these as Markov tasks will cause them to be called\n      both as tasks AND on stop/start, which is usually not what the user intended.\n    - \"run\": This method is used internally by Locust and must not be overridden or\n      annotated with transitions.\n\n    :param decorated_func: The function to validate\n    :raises Exception: If the function name is \"run\"\n    \"\"\"\n    if decorated_func.__name__ in [\"on_stop\", \"on_start\"]:\n        logging.warning(\n            \"You have tagged your on_stop/start function with @transition. This will make the method get called both as a step AND on stop/start.\"\n        )  # this is usually not what the user intended\n    if decorated_func.__name__ == \"run\":\n        raise Exception(\n            \"TaskSet.run() is a method used internally by Locust, and you must not override it or annotate it with transitions\"\n        )\n\n\ndef validate_markov_chain(tasks: list, class_dict: dict, classname: str):\n    \"\"\"\n    Runs all validation functions on a Markov chain.\n\n    :param tasks: List of Markov tasks to validate\n    :param class_dict: Dictionary containing class attributes and methods\n    :param classname: Name of the class being validated (for error/warning messages)\n    :raises: Various exceptions if validation fails\n    \"\"\"\n    validate_has_markov_tasks(tasks, classname)\n    validate_transitions(tasks, class_dict, classname)\n    validate_no_unreachable_tasks(tasks, class_dict, classname)\n    for task in tasks:\n        validate_task_name(task)","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/user/markov_taskset.py#L235-L271","documentation":"TaskSet.run() is Locust's internal execution loop. Overriding it — or annotating a method named 'run' with @transition — would corrupt the MarkovTaskSet machinery, so validate_task_name raises immediately when a decorated function is named 'run'.","triggerScenarios":"Defining 'def run(self):' decorated with @task/@transition inside a MarkovTaskSet; porting a TaskSet that overrode run() to MarkovTaskSet.","commonSituations":"Naming a task 'run' because the domain action is called that (e.g. 'run job'); copy-pasted legacy TaskSet code that overrode run for custom looping.","solutions":["Rename the method to something else, e.g. 'run_job', and update transitions accordingly","Move any custom loop logic out of run() — let Locust's TaskSet.run drive the chain","If you need lifecycle behavior, use on_start/on_stop instead of overriding run"],"exampleFix":"// before\n@task\n@transition(MyUser.next)\ndef run(self): ...\n// after\n@task\n@transition(MyUser.next)\ndef run_job(self): ...","handlingStrategy":"validation","validationCode":"assert not any(name == \"run\" for name in vars(MyUser)), \"'run' is reserved in MarkovTaskSet\"","typeGuard":null,"tryCatchPattern":"try:\n    user = MyUser(env)\nexcept Exception as e:\n    if \"must not override\" in str(e):\n        logging.error(\"Rename the 'run' method\")\n    raise","preventionTips":["Avoid method names matching TaskSet internals (run, on_start, on_stop)","Name domain actions descriptively (run_job, run_report)","Check Locust TaskSet docs for reserved method names"],"tags":["locust","markov-taskset","reserved-method","naming"],"backgroundTag":"reserved-method-override","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}