Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Classes with Empty Tasks Results in TypeError: 'NoneType' object is not iterable #2694

Closed
2 tasks done
hangonlyra opened this issue Apr 30, 2024 · 2 comments
Closed
2 tasks done
Labels

Comments

@hangonlyra
Copy link
Contributor

hangonlyra commented Apr 30, 2024

Prerequisites

Description

After upgrading from 2.19.0 to 2.25.0 (this bug exists in 2.21.0+), I get

Traceback (most recent call last):
  File "/Users/hang/Source/qa_automation/performance/playwright/env/bin/locust", line 8, in <module>
    sys.exit(main())
  File "/Users/hang/Source/qa_automation/performance/playwright/env/lib/python3.8/site-packages/locust/main.py", line 493, in main
    web_ui = environment.create_web_ui(
  File "/Users/hang/Source/qa_automation/performance/playwright/env/lib/python3.8/site-packages/locust/env.py", line 186, in create_web_ui
    self.web_ui = WebUI(
  File "/Users/hang/Source/qa_automation/performance/playwright/env/lib/python3.8/site-packages/locust/web.py", line 142, in __init__
    self.update_template_args()
  File "/Users/hang/Source/qa_automation/performance/playwright/env/lib/python3.8/site-packages/locust/web.py", line 630, in update_template_args
    {
  File "/Users/hang/Source/qa_automation/performance/playwright/env/lib/python3.8/site-packages/locust/web.py", line 631, in <dictcomp>
    user_class_name: [task.__name__ for task in user_class]
TypeError: 'NoneType' object is not iterable

This was trace back to an User class that has no tasks defined. The reason that class exists in my project is because all my other user classes inherit from it.

The fix is actually very simple too:

In locust/main.py, on line 129 change

available_user_tasks[key] = value.tasks or None

to

available_user_tasks[key] = value.tasks or []

since everywhere else available_user_tasks is expected to be iterable.

For now one can just work around it by adding:

@task
def bogus(self):
# Work around for this bug: https://github.com/locustio/locust/issues/2694
    pass

to the class affected by this.

Command line

locust

Locustfile contents

from locust import User

class CustomUser(User):
    pass

Python version

3.8, 3.9, 3.10

Locust version

2.21.0 to 2.25.0

Operating system

Linux or Mac OS

@hangonlyra hangonlyra added the bug label Apr 30, 2024
@cyberw
Copy link
Collaborator

cyberw commented May 1, 2024

Having user classes with no tasks is an error (but shouldnt give this weird crash).

If you dont want instances of a class to be created, just set the abstract = True attribute on the class.

Your fix might still be appropriate but I’m not sure..

@hangonlyra
Copy link
Contributor Author

Oh that's fair. Thanks for the analysis and suggestion. I'll prep a PR. I think it will still be nice to have it not crash like that. Plus the change is minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants