Locust: Using deprecated classes cause a crash

Created on 22 May 2020  ·  6Comments  ·  Source: locustio/locust

Describe the bug

When using a deprecated old name for a class which has been renamed, locust crashes.

Expected behavior

A deprecation warning should be displayed instead, and the original behavior still executed. The user should still have the option to either crash on, notify about or silently ignore usages of deprecated functionality.

For instance, this should by default still work and log a deprecation warning:

class MyLocust(HttpLocust):
    ...

This should be implemented using warnings.warn('<message>', DeprecationWarning) as shown in Python documentation.

Actual behavior

Locust raises a DeprecationWarning exception.

Steps to reproduce

$ python
>>> from locust import HttpLocust
>>> class X(HttpLocust): ...
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "locust/util/deprecation.py", line 23, in __new__
    raise DeprecationWarning(deprecation_message)
DeprecationWarning: The HttpLocust class has been renamed to HttpUser in version 1.0. For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0

Environment

  • OS: Fedora 30
  • Python version: 3.7
  • Locust version: 1.0.1

See also:

bug invalid

Most helpful comment

Thanks for your replies @cyberw and @heyman,

If the old class names are obsoleted, the exception should be different. Maybe an ImportError with an extended message explaining the rename?

As said, DeprecationWarning isn't meant to be raised as an exception which terminates execution, but to be used together with warnings.warn().

As you can see e.g. from the Software deprecation article on Wikipedia, "deprecation" really means that a feature is _going_ to be removed while it still works in the version you're using.

Anyway, we can easily change the class name in our code. I just wanted to point out this confusion for the benefit of other users who hit the issue.

All 6 comments

Hi! Is there something preventing you from changing from HttpLocust to HttpUser in your locustfile?

The intention is not to support the old class names, but just give a more helpful error message. Perhaps we should have chosen to raise some other exception though, but the behaviour is the intended one (crash, not warn).

Like heyman said, this behaviour is very much intentional. Please update your locustfile as suggested or stay on an old version (pip install locustio==0.14.6). Technically it is not "deprecated" but replaced, but I think people will understand.

Thanks for your replies @cyberw and @heyman,

If the old class names are obsoleted, the exception should be different. Maybe an ImportError with an extended message explaining the rename?

As said, DeprecationWarning isn't meant to be raised as an exception which terminates execution, but to be used together with warnings.warn().

As you can see e.g. from the Software deprecation article on Wikipedia, "deprecation" really means that a feature is _going_ to be removed while it still works in the version you're using.

Anyway, we can easily change the class name in our code. I just wanted to point out this confusion for the benefit of other users who hit the issue.

You are completely right! It just doesnt bother me enough to take the time to fix it myself... I'd be happy to merge a PR about this though.

@akaihola Ah, you're right. My mental definition of "deprecation" was a bit off apparently. Even though the Wikipedia article do give some support for my (previous) understanding of it (that it could also mean something that was obsolete) in a single sentence without citation 😄:

The term deprecated may also be used when a technical term becomes obsolete, either through change or supersession

Anyway, I've now changed (c4bdbd30a52273498a400c19c2ef3672f9fd46ed) so that we're raising an ImportError instead.

Thanks for reporting it!

Was this page helpful?
0 / 5 - 0 ratings