Every time I'm using the django-admin command — even on TAB–completion — it throws a RemovedInDjango19Warning (and a lot more if I use the test command). How can I suppress those warnings?
I'm using Django 1.8 with Python 3.4 (in a virtual environment). As far as I can tell, all those warnings come from libraries not from my code.
Examples
Here are some examples:
…/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
return f(*args, **kwds)
…/lib/python3.4/site-packages/django/contrib/admin/util.py:7: RemovedInDjango19Warning: The django.contrib.admin.util module has been renamed. Use django.contrib.admin.utils instead.
"Use django.contrib.admin.utils instead.", RemovedInDjango19Warning)
…/lib/python3.4/site-packages/django/templatetags/future.py:25: RemovedInDjango19Warning: Loading the ``url`` tag from the ``future`` library is deprecated and will be removed in Django 1.9. Use the default ``url`` tag instead.
RemovedInDjango19Warning)
Update
Since Django version 1.11 (release notes) deprecating warnings are no longer loud by default. So I guess this won't be an issue anymore, since 1.11 is the last version to support Python 2 and also features long-term support.
Adding a logging filter to settings.py can suppress these console warnings (at least for manage.py commands in Django 1.7, Python 3.4).
A filter can selectively suppress warnings. The following code creates a new "suppress_deprecated" filter for the console and appends it to the default logging filters. Add this block to settings.py to configure the LOGGING variable:
import logging, copy
from django.utils.log import DEFAULT_LOGGING
LOGGING = copy.deepcopy(DEFAULT_LOGGING)
LOGGING['filters']['suppress_deprecated'] = {
'()': 'mysite.settings.SuppressDeprecated'
}
LOGGING['handlers']['console']['filters'].append('suppress_deprecated')
class SuppressDeprecated(logging.Filter):
def filter(self, record):
WARNINGS_TO_SUPPRESS = [
'RemovedInDjango18Warning',
'RemovedInDjango19Warning'
]
# Return false to suppress message.
return not any([warn in record.getMessage() for warn in WARNINGS_TO_SUPPRESS])
The 'mysite.settings.SuppressDeprecated' string needs to change if the root website module (or filter location and/or name) is different.
In django 1.7, a new setting was introduced SILENCED_SYSTEM_CHECKS to suppress warnings
A list of identifiers of messages generated by the system check
framework (i.e. ["models.W001"]) that you wish to permanently
acknowledge and ignore. Silenced warnings will no longer be output to
the console; silenced errors will still be printed, but will not
prevent management commands from running.
Documentation could be found here
Here is a list of all the checks to suppress
Example:
If you wish to suppress the TEMPLATES_ warning,
The standalone TEMPLATE_* settings were deprecated in Django 1.8
your settings would be:
SILENCED_SYSTEM_CHECKS = ["1_8.W001"]
I'll leave this for newcomers:
As for django 1.11 deprecating warnings are no longer loud by default. To activate them run python -Wd manage.py runserver for example.
source
In manage.py, add this to the top line --
#!/usr/bin/env PYTHONWARNINGS=ignore python
This will suppress all warnings, which I agree can in some situations be undesirable if you're using a lot of third party libraries.
Disclaimer: Recommended only after you've already seen the warnings at least 1,000 too many times already, and should be removed when you upgrade Django.
Note: this may have some undesirable effects on some platforms, eg swallowing more output than just warnings.
Nothing of the above have worked for me, django 1.9. I fixed this by adding the following lines to settings.py:
import logging
def filter_deprecation_warnings(record):
warnings_to_suppress = [
'RemovedInDjango110Warning'
]
# Return false to suppress message.
return not any([warn in record.getMessage()
for warn in warnings_to_suppress])
warn_logger = logging.getLogger('py.warnings')
warn_logger.addFilter(filter_deprecation_warnings)
While reviewing deprecation warnings in other dependencies of my Django 1.8 project, using
python -Wd manage.py runserver
, I was able to filter out Django deprecation warnings by temporarily adding
import warnings
from django.utils.deprecation import RemovedInDjango110Warning
warnings.filterwarnings(action="ignore", category=RemovedInDjango110Warning)
to my settings.py (can presumably be in any module that's loaded at startup). I couldn't figure out how to include the filter as an extra -W option, i.e.
python -Wd -Wi::RemovedInDjango110Warning manage.py runserver
resulted in Invalid -W option ignored: unknown warning category: 'RemovedInDjango110Warning'.
For a quick command-line interface only solution, preface manage.py with python -W ignore when executing, as in:
python -W ignore manage.py runserver
-or-
python -W ignore manage.py shell_plus
-or-
python -W ignore manage.py makemigrations
This is working for me now, to suppress all of the Django 1.10 deprecation warnings while running Django 1.9.
For some reason the solution provided by Fred Schleifer didn't work for me in Django 1.9, so I had to find a different solution.
In settings.py, I set up a custom LOGGING_CONFIG function:
LOGGING_CONFIG = 'my_project.logging_utils.configure'
Then I defined my custom my_project.logging_utils module like so:
from logging.config import dictConfig
import warnings
from django.utils.deprecation import RemovedInDjango110Warning
IGNORE_DJANGO_110_WARNINGS = {
# This is a specific warning raised by a third-party library.
r'rest_framework_swagger\.urls': r'django\.conf\.urls\.patterns\(\) is deprecated.*'
}
def configure(settings):
dictConfig(settings)
for module, message in IGNORE_DJANGO_110_WARNINGS.items():
warnings.filterwarnings(
action='ignore',
category=RemovedInDjango110Warning,
module=module,
message=message
)
The IGNORE_DJANGO_110_WARNINGS dict contains a mapping from module names to regular expressions of warnings raised by them. I chose to be very specific in the kinds of warnings I suppressed, as I still wanted to see ones that I didn't expect. As individual third-party libraries are updated, I'll remove their associated entries from the dict.
# in settings.py
import warnings
from django.utils.deprecation import RemovedInDjango20Warning
DEBUG = True
if DEBUG:
warnings.simplefilter('default')
warnings.filterwarnings('ignore', category=RemovedInDjango20Warning)
# use it if you annoyed by DeprecationWarning
warnings.filterwarnings('ignore', category=DeprecationWarning)
This standart django script add TAB–completion for you bash - https://github.com/django/django/blob/master/extras/django_bash_completion
PYTHONWARNINGS is not defined - error in console. Add export PYTHONWARNINGS="ignore" and unset PYTHONWARNINGS in _django_completion()
Original function:
_django_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
DJANGO_AUTO_COMPLETE=1 $1 ) )
}
My version. Do not break the basic behavior in other cases.
_django_completion()
{
export PYTHONWARNINGS="ignore"
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
DJANGO_AUTO_COMPLETE=1 $1 ) )
unset PYTHONWARNINGS
}
Django puts warnings through the standard python warnings module. If your python project throws warnings and they're "acceptable" for the moment, just use warnings.filterwarnings() or warnings.simplefilter(). I'm not sure where the "best" place for these are, but I've dropped them into my common_settings.py file (For me, this is a unchanging, checked-in file, that is imported by local_settings.py).
Eg:
warnings.filterwarnings(action="ignore", category=RemovedInDjango110Warning, module='django.template.utils', lineno=37)
Alas the comment about silencing the system checks won't work, here, since your example isn't throwing a system-check error.
I currently encounter this same issue when using Django 1.8. Instead of completely suppress those warnings, we decide to show them only in DEBUG mode.
We can add console handler in logging settings and use this handler to catch py.warnings. Here is the code snippet,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue'
},
...
},
'handlers': {
'console': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'standard',
},
...
},
'loggers': {
'py.warnings': {
'handlers': ['console', ],
'level': 'INFO',
'propagate': False
},
...
}
The complete Django settings file: https://github.com/haiwen/seahub/blob/21c827c68047e13700fe102d22a3f5515b22af89/seahub/settings.py#L484
Time to add another one suggestion here, which worked for me. Django 3.2, but should work on any version.
What worked for me is assuming that the developers would be clever enough to output these to python stderr, not stdout. They were!
So..., just redirect stderr to via a standard bash 2>/dev/null
django-admin findstatic teststatic.css 2>/dev/null
Found 'teststatic.css' here:
/Users/me/kds2/py2/bemyerp/websec/static/websec/nodelinks/teststatic.css
/Users/me/kds2/py2/bemyerp/dist/teststatic.css
Of course, bear in mind your context and what this redirection does: suppressing ANY error message. For example, if django-admin is missing, that error message will also disappear (run missing-django-admin findstatic teststatic.css 2>/dev/null to see the effect).
what I was trying to filter out...
HINT: Use django.db.models.JSONField instead.
pssystem.TagType: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Found 'teststatic.css' here:
/Users/me/kds2/py2/bemyerp/websec/static/websec/nodelinks/teststatic.css
/Users/me/kds2/py2/bemyerp/dist/teststatic.css
Things tried without success:
(I am not saying these never work, only that they didn't filter the particular messages I was getting and wanted to avoid, in my environment.
python -W ignore manage.py findstatic teststatic.css
PYTHONWARNINGS=ignore django-admin findstatic teststatic.css
PYTHONWARNINGS=ignore python manage.py findstatic teststatic.css
python -Wd manage.py findstatic teststatic.css
env: Django 3.2, using Python 3.10 with virtualenv
Related
I'm currently trying to implement steam login into website. But I'm unable to get pass this error within the code. I've created the database object but it keeps showing the error I mentioned earlier. I'm not sure whether SQLAlchemy has changed or what since I used it.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
The message emitted by pylint is
E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
EDIT: After read and try np8's answer my previous answer is wrong there is a package you have to install, which is pylint_flask_sqlalchemy
so the answer will be
on your project directory find folder .vscode (if you dont have it, just create it) then create file settings.json and add this line
{
# You have to put it in this order to make it works
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_flask_sqlalchemy",
"pylint_flask", # This package is optional
]
}
You also need to have pylint-flask-sqlalchemy and if you want to use pylint-flask install on your current python environment:
pip install pylint-flask-sqlalchemy
pip install pylint-flask
pip install pylint-flask
In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json as below:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
Summary of working and non-working configurations
It seems that this can be configured so many ways incorrectly, that I decided to write the different options down. I am assuming VS Code, but for command line or other editor, arguments and their order is the same. These were tested using the latest versions of all the packages (list in the bottom of this post)
Working versions
# What you'll need is pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
# You can add pylint_flask but only if it is *AFTER* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
Non-working versions
# pylint_flask does not help, but can break it (see below)
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
# You can NOT add pylint_flask *BEFORE* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
# CAUTION: These will disable pylint silently altogether!
# Do not use dash (-) but underscore (_)!
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy"]
Details for those who are interested
pylint_flask_sqlalchemy
The pylint-flask-sqlalchemy1 was created specifically to fix this2. You can enable it by adding it to --load-plugins of pylint. In command line this would be
python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>
and in VS Code (Settings (JSON)):
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
1Also mirrored to GitHub: https://github.com/anybox/pylint_flask_sqlalchemy
2See this comment on pylint Issue tracker.
pylint_flask
pylint-flask is pylint plugin for Flask. It has nothing to do with Flask-SQLAlchemy and it does not even try to solve the false positive issues pylint has with Flask-SQLAlchemy3. The only possibility to use pylint-flask to "make the errors disappear" is to load it with erroneusly with dashes, which makes the whole pylint to be disabled.
It seems that pylint-flask must be loaded after pylint-flas-sqlalchemy; I tested with my setup, and for some reason
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
will not work, but
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
will. So the order of loading plugins matters.
3 See the code for yourself: pylint-flask source & pylint-flask-sqlaclhemy source
Caution: Do not remove your linting accidentally
As the documentation of pylint-flask and pylint-flask-sqlalchemy says, the names in the argument --load-plugins should be written with underscores; If you use
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
in VS Code, the errors will be gone, but so will be all of your linting as the pylint crashes silently in the background.
Installing pylint-flask-sqlalchemy
pip install pylint-flask-sqlalchemy
Used versions
Flask 1.1.2
Flask-SQLAlchemy 2.4.4
pylint 2.5.3
pylint-flask 0.6
pylint-flask-sqlalchemy 0.2.0
See also
Discussion on pylint GitHub issue: "Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object."
Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:
Python: Select Linter
Switch from PyLint to flake8 or other supported linters.
I've just encountered this issue. Neither of the suggested solutions worked for me, but the following does.
First, install these modules:
pip install pylint-flask
pip install pylint-flask-sqlalchemy
Then, in Visual Studio Code, you need to add the following to your settings.json file:
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
For Windows, this works: In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json ->
and add this code after comma below existing settings:
"python.linting.pylintArgs": [
"--load-plugins",
"pylint-flask"
]
def index(request):
latest_question_list = Question.objects.all().order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = {'latest_question_list':latest_question_list}
return HttpResponse(template.render(context, request))
The first line of that function gets an error on Question.objects.all():
E1101: Class 'Question' has no 'objects' member
I'm following the Django documentation tutorial and they have the same code up and running.
I have tried calling an instance.
Question = new Question()
and using MyModel.objects.all()
Also my models.py code for that class is this...
class Question(models.Model):
question_text = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def __str__(self):
return self.question_text
To no avail I still have this error.
I have read about pylint and ran this...
pylint --load-plugins pylint_django
Which didn't help, even tho the github readme file says...
Prevents warnings about Django-generated attributes such as
Model.objects or Views.request.
I ran the command within my virtualenv, and yet nothing.
So any help would be great.
Install pylint-django using pip as follows
pip install pylint-django
Then in Visual Studio Code goto: User Settings (Ctrl + , or File > Preferences > Settings if available ) Put in the following (please note the curly braces which are required for custom user settings in VSC):
{"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],}
#tieuminh2510's answer is perfect. But in newer versions of VSC you will not find the option to edit or paste that command in User Settings.
For newer versions, add the code in the following steps:
Press ctrl shift p to open the the Command Palette.
Now in Command Palette type Preferences: Configure Language Specific Settings.
Select Python.
Add these lines inside the first curly braces:
"python.linting.pylintArgs": [
"--load-plugins=pylint_django",
]
Make sure that pylint-django is also installed.
Install Django pylint:
pip install pylint-django
ctrl+shift+p > Preferences: Configure Language Specific Settings > Python
The settings.json available for python language should look like the below:
{
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],
"[python]": {
}
}
I've tried all possible solutions offered but unluckly my vscode settings won't changed its linter path. So, I tride to explore vscode settings in settings > User Settings > python. Find Linting: Pylint Path and change it to "pylint_django". Don't forget to change the linter to "pylint_django" at settings > User Settings > python configuration from "pyLint" to "pylint_django".
Heres the answer.
Gotten from my reddit post...
https://www.reddit.com/r/django/comments/6nq0bq/class_question_has_no_objects_member/
That's not an error, it's just a warning from VSC. Django adds that
property dynamically to all model classes (it uses a lot of magic
under the hood), so the IDE doesn't know about it by looking at the
class declaration, so it warns you about a possible error (it's not).
objects is in fact a Manager instance that helps with querying the DB.
If you really want to get rid of that warning you could go to all your
models and add objects = models.Manager() Now, VSC will see the
objects declared and will not complain about it again.
UPDATE FOR VS CODE 1.40.0
After doing:
$ pip install pylint-django
Follow this link: https://code.visualstudio.com/docs/python/linting#_default-pylint-rules
Notice that the way to make pylint have into account pylint-django is by specifying:
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
in the settings.json of VS Code.
But after that, you will notice a lot of new linting errors. Then, read what it said here:
These arguments are passed whenever the python.linting.pylintUseMinimalCheckers is set to true (the default). If you specify a value in pylintArgs or use a Pylint configuration file (see the next section), then pylintUseMinimalCheckers is implicitly set to false.
What I have done is creating a .pylintrc file as described in the link, and then, configured the following parameters inside the file (leaving the rest of the file untouched):
load-plugins=pylint_django
disable=all
enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
Now pylint works as expected.
You can change the linter for Python extension for Visual Studio Code.
In VS open the Command Palette Ctrl+Shift+P and type in one of the following commands:
Python: Select Linter
when you select a linter it will be installed. I tried flake8 and it seems issue resolved for me.
Just adding on to what #Mallory-Erik said:
You can place objects = models.Manager() it in the modals:
class Question(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
# ...
def __str__(self):
return self.question_text
question_text = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
objects = models.Manager()
Change your linter to - flake8 and problem will go away.
I was able to update the user settings.json
On my mac it was stored in:
~/Library/Application Support/Code/User/settings.json
Within it, I set the following:
{
"python.linting.pycodestyleEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "pylint",
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
}
That solved the issue for me.
First install pylint-django using following command
$ pip install pylint-django
Then run the second command as follows:
$ pylint test_file.py --load-plugins pylint_django
--load-plugins pylint_django is necessary for correctly review a code of django
If you use python 3
python3 -m pip install pylint-django
If python < 3
python -m pip install pylint-django==0.11.1
NOTE: Version 2.0, requires pylint >= 2.0 which doesn’t support Python 2 anymore! (https://pypi.org/project/pylint-django/)
First, Install pylint-django using pip as follows:
pip install pylint-django
Goto settings.json find and make sure python linting enabled is true
like this:
At the bottom write "python.linting.pylintPath": "pylint_django"like this:
OR,
Go to Settings and search for python linting
make sure Python > Linting: Pylint Enabled is checked
Under that Python > Linting: Pylint Path write pylint_django
How about suppressing errors on each line specific to each error?
Something like this: https://pylint.readthedocs.io/en/latest/user_guide/message-control.html
Error: [pylint] Class 'class_name' has no 'member_name' member
It can be suppressed on that line by:
# pylint: disable=no-member
I installed PyLint but I was having the error Missing module docstringpylint(missing-module-docstring). So I found this answer with this config for pylint :
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=C0111", // missing docstring
"--load-plugins=pylint_django,pylint_celery",
],
And now it works
By doing Question = new Question() (I assume the new is a typo) you are overwriting the Question model with an intance of Question. Like Sayse said in the comments: don't use the same name for your variable as the name of the model. So change it to something like my_question = Question().
This issue happend when I use pylint_runner
So what I do is open .pylintrc file and add this
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=objects
Just add objects = None in your Questions table. That solved the error for me.
When I do my tests with Django 1.7.1 it throws the next warning:
/usr/local/lib/python2.7/dist-packages/django/test/_doctest.py:59:
RemovedInDjango18Warning: The django.test._doctest module is deprecated;
use the doctest module from the Python standard library instead.
RemovedInDjango18Warning)
I also tried adding in the settings.py file this line:
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
But still throws the warning.
I write down the code from my test model file:
from django.test import TestCase
from myproject import tests, models
class TestModels(TestCase):
def test_rol(self):
rol = tests.create_rol()
rol.save()
self.assertTrue(isinstance(rol, models.Rol))
self.assertEqual(rol.name, rol.__unicode__())
I have read the docs from the Django Web page: https://docs.djangoproject.com/en/1.7/topics/testing/overview/ but still can't get a solution.
I am using Django-nose.
How can I solve this?
Thanks
This is a problem in the django-nose package (see GitHub issue #149). It has been fixed in master, but there is no PyPI release for it yet. For now, if you don't want to see the warning, you can point your requirements.txt file to the fixed version:
-e git://github.com/django-nose/django-nose.git#154b663097e8f3131fe5d1cdd8a8df2e388450ac#egg=django_nose
... instead of ...
django-nose==1.2
Update: django-nose 1.3 has been released and contains this fix.
It looks like this is a django-nose issue: see here.
So, just ignore it. Presumably it will be fixed before you're actually using Django 1.8.
This below command errors generates when i run my program with this command python manage.py runserver
/usr/local/lib/python2.7/dist-packages/cms/context_processors.py:20: DeprecationWarning:
cms.context_processors.media has been deprecated in favor of
cms.context_processors.cms_settings. Please update your configuration
'configuration', DeprecationWarning)
How to solve this error?
Follow instructions provided here http://django-cms.readthedocs.org/en/latest/upgrade/3.0.html#cms-context-processors-media .
Your project probably has settings.py file which contains TEMPLATE_CONTEXT_PROCESSORS variable (a list of content processors). This list contains "cms.context_processors.media", it should be replaced with "cms.context_processors.cms_settings".
So, I get the following output while running the tests for my Django project:
WARNING 2013-04-25 17:55:29,977 18482 29789392 py.warnings:3 <module>() /home/sean/dev/project/testenv/local/lib/python2.7/site-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
DeprecationWarning)
WARNING 2013-04-25 17:55:29,986 18482 29789392 py.warnings:10 <module>() /home/sean/dev/project/testenv/local/lib/python2.7/site-packages/django/utils/copycompat.py:10: DeprecationWarning: django.utils.copycompat is deprecated; use the native copy module instead
DeprecationWarning)
I'd like to figure out where in my code, or in what dependencies, these are originating.
http://docs.python.org/2/library/warnings.html
According to this, I can do the following to make Warnings be thrown as Exception and get a traceback:
At the top of my manage.py, before any other code is called:
import warnings
warnings.filterwarnings(
'error', r".*",
Warning, r'.*')
This causes "PendingDeprecationWarning: django.utils.simplejson is deprecated; use json instead." to be thrown, so I used:
import warnings
warnings.filterwarnings(
'error', r".*",
Warning, r'.*')
warnings.filterwarnings(
'ignore', r".*",
Warning, r'django\.utils\.simplejson')
But it's still printing out the previous DeprecationWarnings and not raising them as errors like it's supposed to.
Edit:
Also, I tried putting print and pdb statements at the beginning of warnings.warn_explicit(), the place where the filter logic happens, and they never get called.
You could run the tests or the local django server with the -W error option:
$ python -W error manage.py runserver
or
$ python -W error manage.py test
That will treat warnings as errors.