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

Always use warnings.warn for deprecation messages. #4109

Open
antonpirker opened this issue Feb 28, 2025 · 1 comment · May be fixed by #4110
Open

Always use warnings.warn for deprecation messages. #4109

antonpirker opened this issue Feb 28, 2025 · 1 comment · May be fixed by #4110
Assignees

Comments

@antonpirker
Copy link
Member

Make all deprecation messages use the warnings.warn function.

Right now we use two different ways, some deprecation messages use logging.warning and some are using warnings.warn.

There was some discussion about using logging or warnings module for deprecation. In the Python world, warnings module is the most use way to do deprecation. Here are some arguments that where taken into account when deciding to use warnings module over logging:

  • When running normal (python manage.py runserver 0.0.0.0:8000)

    • Logging deprecations ARE printed (every time they appear)
    • Warnings deprecations are NOT printed.
  • When deprecation warnings enabled (python -Wd manage.py runserver 0.0.0.0:8000)

    • Logging deprecations ARE printed. (every time they appear)
    • Warnings deprecations ARE printed. (only printed ONCE, the first time it is emmited.)
  • When running tests (pytest ...)

    • Logging deprecations ARE printed (when the test fails)
    • Warnings deprecations ARE printed.
    • Tests DO NOT FAIL!
  • When running tests and treating errors as warnings (pytest -W error) This is what we are doing in sentry repo.

    • Logging deprecations ARE printed (when the test fails)
    • Logging deprecations are NOT breaking the test run.
    • Warnings deprecations ARE printed.
    • Warnings deprecations ARE breaking the test run.
    • Deprecation warnings from certain packages can be ignored by adding this to pytest.ini:
    filterwarnings =
        error ; turn warnings into errors
        ; ignore::DeprecationWarning:polls.*  ; if users call deprecated sentry function from their code they also need to ignore depreactions from their module
        ignore::DeprecationWarning:sentry_sdk.* ; ignore deprecations from sentry_sdk

All in all:

  • warnings are not shown in the default case (which is good, we do not want to annoy users)
  • warnings are only emitted once (compared to logging, where every call will be logged, so warnings do not spam the users logs that much
  • warnings are printed by default when running tests. This is OK.
  • There is fine grained settings for showing/hiding warnings and also a lot of tooling supports warnings.
@antonpirker
Copy link
Member Author

After talking to @sentrivana we agreed on to not release this in a minor, but the next major.

People using pytest -W error right now would get a failing test suite after upgrading, and we do not want that.

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

Successfully merging a pull request may close this issue.

1 participant