#25477: Modelbase.__new__ causes `AppRegistryNotReady`
---------------------------------+--------------------
Reporter: cdestigter | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.9a1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
I'm probably missing something, but I've noticed a regression when testing
1.9.
My standalone app django-typed-models gets this stack trace on django
1.9a1:
{{{#!python
Traceback (most recent call last):
File "./runtests.py", line 12, in <module>
django.setup()
File ".../site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File ".../site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File ".../site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py",
line 37, in import_module
__import__(name)
File "./typedmodels/__init__.py", line 2, in <module>
from .models import TypedModel
File "./typedmodels/models.py", line 301, in <module>
class TypedModel(with_metaclass(TypedModelMetaclass, models.Model)):
File ".../site-packages/django/utils/six.py", line 778, in __new__
return meta(name, bases, d)
File "./typedmodels/models.py", line 49, in __new__
typed_model = super(TypedModelMetaclass, meta).__new__(meta,
classname, bases, classdict)
File ".../site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File ".../site-packages/django/apps/registry.py", line 239, in
get_containing_app_config
self.check_apps_ready()
File ".../site-packages/django/apps/registry.py", line 124, in
check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
}}}
It looks like `ModelBase.__new__` is calling
`apps.get_containing_app_config`, and that calls `check_apps_ready` which
throws the exception.
But, AFAICT the app-loading process imports the models, so it seems
obvious that the apps aren't ever ready when the models are being defined.
It seems if I remove [https://github.com/craigds/django-typed-
models/blob/master/typedmodels/__init__.py#L2 this line] from my app, the
problem goes away.
I'm hesitant to do that because it'd be backwards-incompatible for users
of my app (and `from typedmodels import TypedModel` is much less
repetitive than `from typedmodels.models import TypedModel`)
If importing the models file from the `__init__.py` is really no longer
supported, perhaps a note should be added to the django 1.9 release notes
about it?
--
Ticket URL: <https://code.djangoproject.com/ticket/25477>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.7e211b7d83be585572123789ce631033%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.