Domanda

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?

È stato utile?

Soluzione 2

This is taken from a similar question.

You can use the warnings modules to raise an error for DeprecationWarning.

Temporarily add the following snippet to the top of your project's urls.py:

import warnings
warnings.simplefilter('error', DeprecationWarning)

The DeprecationWarning will now raise an error, so if debug=True you'll get the familiar yellow Django error page with the full traceback.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top