﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25477	Modelbase.__new__ causes `AppRegistryNotReady`	Craig de Stigter	nobody	"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?
"	Bug	closed	Core (Other)	1.9	Normal	wontfix			Accepted	0	0	0	0	0	0
