It turned out to be caused by circular imports. I can't even imagine how
circular imports would cause the "Apps aren't loaded" exception, but
needless to say, that error message doesn't describe the actual situation.
If possible, could circular imports be detected and an appropriate
response given?
--
Ticket URL: <https://code.djangoproject.com/ticket/31560>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: (none) => nobody
* resolution: => needsinfo
* status: new => closed
* component: Error reporting => Core (Other)
Comment:
Thanks for this report, Can you provide a sample project? All my attempts
raise an `ImportError` (even with circular imports in `apps.py`)
--
Ticket URL: <https://code.djangoproject.com/ticket/31560#comment:1>
Comment (by ExTexan):
In one of my cases, it was a model imported in a signals.py and the
signals.py imported by the same model it imported. Then anything that
tried to import the model would encounter the circular imports. As a
quick test, I just went back to the signals.py file and put the model
import back in. I got ImportError, as you did. There were a slew of
changes I made when I fixed the "Apps aren't loaded yet" issue, so now I
can't be sure what actually caused it in the first place.
I'll need to revert that entire commit and take it one step at a time to
see if I can zero in on the cause. I'll see if I can make time to do
this, but workload is heavy atm, so I can't really say when I'll get to
it.
--
Ticket URL: <https://code.djangoproject.com/ticket/31560#comment:2>
Comment (by Heraldo Lucena):
Replying to [comment:1 felixxm]:
> Thanks for this report, Can you provide a sample project? All my
attempts raise an `ImportError` (even with circular imports in `apps.py`)
I had this problem and managed to debug it right now. It will happen when
Django's app registry imports the app's module added in INSTALLED_APPS and
that module imports, directly or indirectly, a model of the app being
loaded. Reading the docs
[https://docs.djangoproject.com/en/3.0/ref/applications/] there are no
notes warning about it.
**Steps to reproduce**
1. Create a django project and one app
2. Create a Model in app/models.py
3. In {{{ app/__init__.py }}} import the created model
4. Add the app's dotted path to INSTALLED_APPS
5. Try to run with {{{ ./manage.py runserver }}}
You will get the error {{{ django.core.exceptions.AppRegistryNotReady:
Apps aren't loaded yet. }}}
Since it's caused by Django, I think Django should be able to detect it
and output a meaning error message
--
Ticket URL: <https://code.djangoproject.com/ticket/31560#comment:3>