locustio/locust · error · Exception

No tasks defined on {self.user.__class__.__name__}{extra_mes

Error message

No tasks defined on {self.user.__class__.__name__}{extra_message} Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)

What it means

User.get_next_task() (for User-based, non-TaskSet users) requires the User class to have tasks. If the User has no tasks and no `task` attribute, it raises, suggesting @task or the tasks attribute, or marking the class abstract.

Source

Thrown at locust/user/task.py:502

        """
        Shortcut to the client :py:attr:`client <locust.User.client>` attribute of this TaskSet's :py:class:`User <locust.User>`
        """
        return self.user.client


class DefaultTaskSet(TaskSet):
    """
    Default root TaskSet that executes tasks in User.tasks.
    It executes tasks declared directly on the Locust with the user instance as the task argument.
    """

    def get_next_task(self):
        if not self.user.tasks:
            if getattr(self.user, "task", None):
                extra_message = ", but you have set a 'task' attribute on your class - maybe you meant to set 'tasks'?"
            else:
                extra_message = "."
            raise Exception(
                f"No tasks defined on {self.user.__class__.__name__}{extra_message} Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)"
            )
        return random.choice(self.user.tasks)

    def execute_task(self, task):
        if hasattr(task, "tasks") and issubclass(task, TaskSet):
            # task is  (nested) TaskSet class
            task(self.user).run()
        else:
            # task is a function
            task(self.user)

View on GitHub (pinned to f391a716e1)

Solutions

  1. Add @task-decorated methods to the User
  2. Set `tasks = [...]` on the User
  3. Fix `task` to `tasks` if the singular attribute was set
  4. Set `abstract = True` on User classes meant only as base classes

Example fix

// before
class MyBaseUser(User):
    task = [do_thing]
// after
class MyBaseUser(User):
    abstract = True
class MyUser(MyBaseUser):
    tasks = [do_thing]
Defensive patterns

Strategy: validation

Validate before calling

assert getattr(MyUser, 'tasks', None) or getattr(MyUser, 'abstract', False) or any(callable(v) and getattr(v, 'locust_task_weight', None) for v in vars(MyUser).values()), "User has no tasks"

Prevention

When it happens

Trigger: Running a User subclass with no @task methods and no `tasks` list; or setting singular `task` instead of `tasks`.

Common situations: Instantiating base/shared User classes intended only for subclassing; refactoring removed all tasks; typo `task = [...]`.

Related errors


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/589bdbf2e70499c8. Report an issue: GitHub.