#22005 closed Bug (fixed)
PendingDeprecationWarning with management commands.
Reported by: | loic84 | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Release blocker | Keywords: | app-loading |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
These happen on a fresh startproject
created for the occasion and with any management command.
$ python -Wall ./manage.py validate /Users/loic/Dev/django/django/contrib/contenttypes/models.py:131: PendingDeprecationWarning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class ContentType(models.Model): /Users/loic/Dev/django/django/contrib/auth/models.py:40: PendingDeprecationWarning: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class Permission(models.Model): /Users/loic/Dev/django/django/contrib/auth/models.py:95: PendingDeprecationWarning: Model class django.contrib.auth.models.Group doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class Group(models.Model): /Users/loic/Dev/django/django/contrib/auth/models.py:191: PendingDeprecationWarning: Model class django.contrib.auth.models.AbstractBaseUser doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. Its app_label will be set to None in Django 1.9. class AbstractBaseUser(models.Model): /Users/loic/Dev/django/django/contrib/auth/models.py:278: PendingDeprecationWarning: Model class django.contrib.auth.models.PermissionsMixin doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. Its app_label will be set to None in Django 1.9. class PermissionsMixin(models.Model): /Users/loic/Dev/django/django/contrib/auth/models.py:353: PendingDeprecationWarning: Model class django.contrib.auth.models.AbstractUser doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. Its app_label will be set to None in Django 1.9. class AbstractUser(AbstractBaseUser, PermissionsMixin): /Users/loic/Dev/django/django/contrib/auth/models.py:405: PendingDeprecationWarning: Model class django.contrib.auth.models.User doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class User(AbstractUser): System check identified no issues (0 silenced).
fb1e3435a4d7e0265f19a1a9f130c9485fb8dfe9 is a "bad" commit, ab922c5cd84d3bde09917b72cfddd8c6a4985f26 is a "good" commit, bisect blames d4a5019bef116028edb6e66eac9156da96a3d704. Sadly, since bisect unveils a docs-only commit, it may be one of those issue that is hard to reproduce.
Change History (11)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Not sure if that's the way to go, but we definitely should order them according to their dependencies…
follow-up: 7 comment:3 by , 11 years ago
Keywords: | app-loading added |
---|---|
Triage Stage: | Unreviewed → Accepted |
I disagree with this approach. It masks the issue for new projects without addressing it in all existing projects!
This commit makes the assumption that apps must be ordered according to dependencies. This is backwards-incompatible and we've made a decision *not* to require this. It should be reverted.
I recently made changes to avoid importing ContentType at import time. If that problem crops up again, the import must be identified and delayed until runtime.
Loic, can you run the same code under "python -Werror" to obtain a full stack trace when you hit the first warning, and figure out where it comes from?
comment:4 by , 11 years ago
Full traceback:
$ python -Werror ./manage.py validate Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/loic/Dev/django/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/Users/loic/Dev/django/django/core/management/__init__.py", line 391, in execute django.setup() File "/Users/loic/Dev/django/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/loic/Dev/django/django/apps/registry.py", line 84, in populate app_config = AppConfig.create(entry) File "/Users/loic/Dev/django/django/apps/config.py", line 87, in create module = import_module(entry) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/loic/Dev/django/django/contrib/admin/__init__.py", line 10, in <module> from django.contrib.admin.sites import AdminSite, site File "/Users/loic/Dev/django/django/contrib/admin/sites.py", line 5, in <module> from django.contrib.auth.views import redirect_to_login File "/Users/loic/Dev/django/django/contrib/auth/views.py", line 16, in <module> from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, PasswordChangeForm File "/Users/loic/Dev/django/django/contrib/auth/forms.py", line 16, in <module> from django.contrib.auth.models import User File "/Users/loic/Dev/django/django/contrib/auth/models.py", line 16, in <module> from django.contrib.contenttypes.models import ContentType File "/Users/loic/Dev/django/django/contrib/contenttypes/models.py", line 131, in <module> class ContentType(models.Model): File "/Users/loic/Dev/django/django/db/models/base.py", line 117, in __new__ warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) PendingDeprecationWarning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
comment:5 by , 11 years ago
We could move the import of ContentType
inside get_by_natural_key
and use a lazy reference in the ForeignKey
(ie. 'contenttypes.ContentType'
).
comment:6 by , 11 years ago
I did https://gist.github.com/8932470, now getting:
$ python -Werror ./manage.py validate Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/loic/Dev/django/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/Users/loic/Dev/django/django/core/management/__init__.py", line 391, in execute django.setup() File "/Users/loic/Dev/django/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/loic/Dev/django/django/apps/registry.py", line 84, in populate app_config = AppConfig.create(entry) File "/Users/loic/Dev/django/django/apps/config.py", line 87, in create module = import_module(entry) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/loic/Dev/django/django/contrib/admin/__init__.py", line 10, in <module> from django.contrib.admin.sites import AdminSite, site File "/Users/loic/Dev/django/django/contrib/admin/sites.py", line 5, in <module> from django.contrib.auth.views import redirect_to_login File "/Users/loic/Dev/django/django/contrib/auth/views.py", line 16, in <module> from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, PasswordChangeForm File "/Users/loic/Dev/django/django/contrib/auth/forms.py", line 16, in <module> from django.contrib.auth.models import User File "/Users/loic/Dev/django/django/contrib/auth/models.py", line 43, in <module> class Permission(models.Model): File "/Users/loic/Dev/django/django/db/models/base.py", line 117, in __new__ warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) PendingDeprecationWarning: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
follow-up: 8 comment:7 by , 11 years ago
Replying to aaugustin:
I disagree with this approach. It masks the issue for new projects without addressing it in all existing projects!
Yes, hence I left this ticket open ;)
It should be reverted.
Ok, please do so when committing a fix for it.
I recently made changes to avoid importing ContentType at import time. If that problem crops up again, the import must be identified and delayed until runtime.
To be honest I am not super fond of moving imports into functions/methods till we no longer run into issues; do we have any other way of restructuring?
comment:8 by , 11 years ago
Replying to apollo13:
To be honest I am not super fond of moving imports into functions/methods till we no longer run into issues; do we have any other way of restructuring?
One alternative might be to change the decision on #21719 and not try to restrict early imports of models.py
. Hypothetically this is what I would prefer, as I commented there, but there were good reasons Aymeric chose to do it this way, so until I have (or someone has) time to dive in and attempt a patch, that option remains hypothetical.
comment:9 by , 11 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is really a duplicate of #21719.
comment:11 by , 11 years ago
Resolution: | duplicate → fixed |
---|
In a718fcf201b04ba254e9073be82f51ae1ae3a853: