Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22402 closed Bug (fixed)

Deprecation warnings with model_inheritance

Reported by: Tim Graham Owned by: Aymeric Augustin
Component: Database layer (models, ORM) Version: 1.7-beta-1
Severity: Release blocker Keywords: app-loading
Cc: loic@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

The warnings below appear before the test databases are created. If I delete the tests/model_inheritance_same_model_name directory, they disappear. Aymeric said he could not reproduce so this may only affect some systems but it happens for me on my local machine, on the rebuild of Jenkins I am working on, and with the djangocore-box.

/home/tim/code/django/tests/model_inheritance/models.py:25: RemovedInDjango19Warning: Model class model_inheritance.models.CommonInfo 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 CommonInfo(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:37: RemovedInDjango19Warning: Model class model_inheritance.models.Worker 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 Worker(CommonInfo):
/home/tim/code/django/tests/model_inheritance/models.py:41: RemovedInDjango19Warning: Model class model_inheritance.models.Student 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 Student(CommonInfo):
/home/tim/code/django/tests/model_inheritance/models.py:52: RemovedInDjango19Warning: Model class model_inheritance.models.Post 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 Post(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:57: RemovedInDjango19Warning: Model class model_inheritance.models.Attachment 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 Attachment(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:68: RemovedInDjango19Warning: Model class model_inheritance.models.Comment 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 Comment(Attachment):
/home/tim/code/django/tests/model_inheritance/models.py:72: RemovedInDjango19Warning: Model class model_inheritance.models.Link 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 Link(Attachment):
/home/tim/code/django/tests/model_inheritance/models.py:81: RemovedInDjango19Warning: Model class model_inheritance.models.Chef 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 Chef(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:89: RemovedInDjango19Warning: Model class model_inheritance.models.Place 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 Place(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:97: RemovedInDjango19Warning: Model class model_inheritance.models.Rating 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 Rating(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:106: RemovedInDjango19Warning: Model class model_inheritance.models.Restaurant 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 Restaurant(Place, Rating):
/home/tim/code/django/tests/model_inheritance/models.py:119: RemovedInDjango19Warning: Model class model_inheritance.models.ItalianRestaurant 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 ItalianRestaurant(Restaurant):
/home/tim/code/django/tests/model_inheritance/models.py:127: RemovedInDjango19Warning: Model class model_inheritance.models.Supplier 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 Supplier(Place):
/home/tim/code/django/tests/model_inheritance/models.py:135: RemovedInDjango19Warning: Model class model_inheritance.models.ParkingLot 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 ParkingLot(Place):
/home/tim/code/django/tests/model_inheritance/models.py:153: RemovedInDjango19Warning: Model class model_inheritance.models.Title 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 Title(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:157: RemovedInDjango19Warning: Model class model_inheritance.models.NamedURL 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 NamedURL(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:166: RemovedInDjango19Warning: Model class model_inheritance.models.Copy 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 Copy(NamedURL):
/home/tim/code/django/tests/model_inheritance/models.py:179: RemovedInDjango19Warning: Model class model_inheritance.models.MixinModel 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 MixinModel(models.Model, Mixin):
/home/tim/code/django/tests/model_inheritance/models.py:183: RemovedInDjango19Warning: Model class model_inheritance.models.Base 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 Base(models.Model):
/home/tim/code/django/tests/model_inheritance/models.py:187: RemovedInDjango19Warning: Model class model_inheritance.models.SubBase 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 SubBase(Base):

Change History (9)

comment:1 by Aymeric Augustin, 10 years ago

Keywords: app-loading added
Owner: changed from nobody to Aymeric Augustin
Severity: NormalRelease blocker
Status: newassigned
Triage Stage: UnreviewedAccepted

Well I shall try to reproduce again...

comment:2 by ANUBHAV JOSHI, 10 years ago

I can reproduce this.
I did python -Wall runtests.py model_inheritance_same_model_name using virtualenv.
Also I am getting along with the above traceback the following also adds up on mine.

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "runtests.py", line 374, in <module>
    options.failfast, args)
  File "runtests.py", line 216, in django_tests
    test_labels or get_installed(), extra_tests=extra_tests)
  File "c:\users\anubhav\django\django\test\runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "c:\users\anubhav\django\django\test\runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "c:\users\anubhav\django\django\test\runner.py", line 297, in setup_databases
    verbosity, autoclobber=not interactive)
  File "c:\users\anubhav\django\django\db\backends\creation.py", line 366, in create_test_db
    test_database=True)
  File "c:\users\anubhav\django\django\core\management\__init__.py", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "c:\users\anubhav\django\django\core\management\base.py", line 336, in execute
    self.check()
  File "c:\users\anubhav\django\django\core\management\base.py", line 413, in check
    raise CommandError(msg)
django.core.management.base.CommandError: System check identified some issues:

ERRORS:
model_inheritance_same_model_name.Copy.title: (fields.E300) Field defines a relation with model 'Title', which is either not installed, or is abstract.

comment:3 by loic84, 10 years ago

model_inheritance_same_model_name import models from model_inheritance, in order to test that related_name with %(app_label)s avoids clashing related models accessor.

Maybe the tests should be rewritten with a controlled App registry where the models and apps are manually added, rather than relying on test packages being apps.

comment:4 by Aymeric Augustin, 10 years ago

Did you try @override_settings(INSTALLED_APPS=['model_inheritance', 'model_inheritance_same_model_name')?

comment:5 by loic84, 10 years ago

No luck with @override_settings, both at the TestCase and at each test method level; even after removing from model_inheritance.models import Title from the module level.

Just started getting the same error as @anubhav9042, oddly enough I wasn't getting it before (only the deprecations). Also it only happens when model_inheritance_same_model_name is run in isolation, not with the whole suite.

comment:6 by loic84, 10 years ago

Cc: loic@… added
Has patch: set
Patch needs improvement: set

Hopefully someone will find a better way to fix this, but in case not, I have https://github.com/loic/django/compare/ticket22402. The change in ModelBase that makes app_label account for any custom Meta.app that may have been provided causes some PendingDeprecationWarning warnings in migrations tests, if we decide to go with this fix, I'll take a look at these.

comment:7 by Aymeric Augustin, 10 years ago

It's a bit of an edge case due to a peculiar test construct. I don't think any changes are required in Django.

We want to test what happens if a model inherits from another model with the same name (I guessed that from the name of the test app).

That requires two models with the same name: the parent and the child.

But you can't have two models with the same name in the same app, given how the app registry works.

So you need two different apps in INSTALLED_APPS. It doesn't make sense to run one without the other.

The proper fix is to restructure the test:

  • by inheriting from a model found in an application that's in ALWAYS_INSTALLED_APPS, or
  • by adding 'model_inheritance' to ALWAYS_INSTALLED_APPS (which seems wrong), or
  • by creating an ad-hoc application and inserting it in tho app registry only for the duration of the test.

by having 'model_inheritance_same_model_name' add a specific app to INSTALLED_APPS

Version 0, edited 10 years ago by Aymeric Augustin (next)

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

Resolution: fixed
Status: assignedclosed

In 3f76339355c1fe550dedf676feddd42a5d48be58:

Fixed #22402 -- Consolidated model_inheritance tests.

The model_inheritance_same_model_name tests couldn't be run without the
model_inheritance tests. Make the problem go away by merging them.

Thanks timo for the report.

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

In ab0afef9590730064d40ca074c3b2be3baebf9cb:

[1.7.x] Fixed #22402 -- Consolidated model_inheritance tests.

The model_inheritance_same_model_name tests couldn't be run without the
model_inheritance tests. Make the problem go away by merging them.

Thanks timo for the report.

Backport of 0097d38 from master

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