Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#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 Florian Apolloner <florian@…>, 10 years ago

In a718fcf201b04ba254e9073be82f51ae1ae3a853:

Reordered INSTALLED_APPS in default template, refs #22005

comment:2 by Florian Apolloner, 10 years ago

Not sure if that's the way to go, but we definitely should order them according to their dependencies…

comment:3 by Aymeric Augustin, 10 years ago

Keywords: app-loading added
Triage Stage: UnreviewedAccepted

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 loic84, 10 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 Aymeric Augustin, 10 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 loic84, 10 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.

in reply to:  3 ; comment:7 by Florian Apolloner, 10 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?

in reply to:  7 comment:8 by Carl Meyer, 10 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 Aymeric Augustin, 10 years ago

Resolution: duplicate
Status: newclosed

This is really a duplicate of #21719.

comment:10 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

In 8b67fa755140fb4a6b961dfa97744286b5262a3c:

Revert "Reordered INSTALLED_APPS in default template, refs #22005"

This reverts commit a718fcf201b04ba254e9073be82f51ae1ae3a853.

comment:11 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

Resolution: duplicatefixed

In 7339f43c718008394cf5c5119994f956e27bce70:

Prevented admin from importing auth.User.

Since we don't enforce order between apps, root packages of contrib apps
cannot import models from unrelated apps.

Fix #22005, refs #21719.

Note: See TracTickets for help on using tickets.
Back to Top