Wednesday, April 29, 2015

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJVQVexAAoJEC0ft5FqUuEhNHYP/joTs0hgPnzYdn9WFqwuOdGG
25vMrFSXNkMbHqIQL2uPdj7JUyXbYJxefR4B8DUAitT1YZbsFt1ckhhaOUopNFJS
W7IDHrTYlYe74wsKQ7mFyBaaFTzZEv7ZlBcOLIkctRwhRPp2YPc7d+LUS+EeB2mL
j6oVAcr5lRQdI+QedMmEKs+QhLyhD7oghYgI8EZDKdZ2vJ47rMbeOSrVstVewTWQ
BPRo9RuNpZXYjoc3Ow+Z5DC4lvaFwq7NM+J6Q3QV62iFUJyqAf/WOWR3KIT9WR53
eRgg370dxCYKvcGiUKkr++h5JF1Vwqnk9f/GrB1PIQZ2t0htw0SQjUQ9+/pu35JE
q4ezW8W4wIeduWBS2wUp4Lto0OE2XrwN5GCWRqnBfuamd1hnCQ1zvEJRjMsJg7HQ
hUEOnxXPLZagwA5+y5QyZVxOYhgFE2oygDBEjlbhejYZVP6hKHKkqbkFCmshk8Jr
n5pmIgP3CZgf9UUd9jJCXGDH0g33EY0xDTvIkZmEE3evWn6rQg58D8jg54cD4h5w
M1z8h+TmVCkse6T9TAfKeXLmErtxU7XDXs6Ll7GFv4Ly3OXYJEJnqDT0fNzygV5w
8xhMZsoN62p2R+OUDlGyK5jzWs5SGubaXMZmA+qYosOFceUPdecV5Fto/pffP2iu
hChzjBqyLxnftkBYf8vH
=7QEa
-----END PGP SIGNATURE-----
Hi,

On 04/29/2015 11:13 AM, Bumyong Choi wrote:
> 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?"

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/554157B1.5000702%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment