Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verbose deprecation warnings in Django

After upgrading from django 1.3 to django 1.5 I started to see these DeprecationWarnings during the test run:

path_to_virtualenv/lib/python2.6/site-packages/django/http/request.py:193: DeprecationWarning: HttpRequest.raw_post_data has been deprecated. Use HttpRequest.body instead.

I've searched inside the project for raw_post_data and found nothing. So it was not directly used in the project. Then, I've manually went through INSTALLED_APPS and found that raven module still uses raw_post_data and it was the cause, but..

Is it possible to see the cause of DeprecationWarning during the test run? How to make these warnings more verbose?

like image 642
alecxe Avatar asked May 05 '13 22:05

alecxe


People also ask

What are deprecation warnings?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.

What does deprecation warning mean in Python?

removing is danger because user may used that and if a developer want to remove a thing first have to notify others to don't use this feature or things and after this he can remove. and DeprecationWarning is this notification.


1 Answers

You can set Python warning control by command line option -W to raise an exception with a traceback on DeprecationWarning like for errors instead of normal simple warning once. Any specific warning can by filtered by message, category, module, line or by a combination of them.

Examples:

python -W error:"raw_post_data has been deprecated" manage.py test

python -W error::DeprecationWarning manage.py test

python -W error:::django.http.request manage.py test

A fine filtering is useful if you want to fix all warnings of one type together by batch editing in many files of a big project.


Python 2.7 and higher ignores DeprecationWarning usually if they are not reanabled, e.g. by -Wd option or by the environment variable export PYTHONWARNINGS="d". That can be useful on development machines but not on production.

like image 187
hynekcer Avatar answered Oct 04 '22 17:10

hynekcer