RemovedInDjango19Warning: Model class %s doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS ..

368 views
Skip to first unread message

Bumyong Choi

unread,
Apr 29, 2015, 2:39:06 PM4/29/15
to django...@googlegroups.com
I am trying to understand this warning better. I understand that we want to make sure that a model has an explicit app_label or it is in INSTALLED_APPS. I spent some time trying to remove warnings from my code because I was getting these warning messages even though my model was defined in an app listed in INSTALLED_APPS. 

After scratching my head for quite some time, I put a breakpoint on the following line of the code in django.db.models.base:



# Look for an application configuration to attach the model to.

app_config = apps.get_containing_app_config(module)


And I checked to see what I get for "app_configs.values()" and I realized that the app is in INSTALLED_APPS but not yet been loaded. This was because one of the third party framework I use was trying to import models before they were loaded. 

My question is the following:

Is Django trying to prevent a model from being imported before this model is actually defined? If this is the case, is it possible to improve the warning so that it would check "INSTALLED_APPS" and warn the user that even if the app is listed there some other app is trying to import the model before the app is loaded?"

If the intention is not as aforementioned, is this a bug?

Thank you

Carl Meyer

unread,
Apr 29, 2015, 6:14:34 PM4/29/15
to django...@googlegroups.com
Hi,
Yes, that is the current intention in Django 1.7+: you may not import a
models.py file before the app cache has been prepared. (I personally
think this is unfortunate, but to change it while maintaining consistent
and predictable semantics would require a deep reworking of how relation
fields are initialized, which nobody has so far attempted).

I'm surprised you are getting that particular error though - if a
models.py file is imported too soon, I would expect an "App registry not
ready" error instead. So it may be a bug that you are getting this error
message instead of that one; hard to know without seeing code to
reproduce the issue.

Carl

signature.asc

Bumyong Choi

unread,
Apr 30, 2015, 4:45:40 PM4/30/15
to django...@googlegroups.com
I attached a sample app here. You need to install django-haystack prior to running the app. haystack lets you define "Haystack Signal Processor". and in this signal processor, it attempts to load one of the models that belong to an app that is listed in INSTALLED_APPS after haystack. I would appreciate it if you could review this and see if it is a legit bug.. I will be more than happy to create a ticket for it.

Thank you
django-test.tgz
Reply all
Reply to author
Forward
0 new messages