[Django] #25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9

6 views
Skip to first unread message

Django

unread,
Dec 4, 2015, 5:42:09 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------
Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Hi,

I have a script which worked in django 1.8
but does no more in django 1.9, I get the exception:
{{{django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet}}}

Unfortunately I didn't find a hint in the release notes

{{{#!py
from myapp.models import MyModel1 # here is the exception
...
if __name__ == "__main__":

import django
django.setup()
# my code follows
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25864>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 4, 2015, 6:13:11 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------

Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by stephanm):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:1>

Django

unread,
Dec 4, 2015, 6:15:43 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------

Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by bmispelon):

Hi,

We can't really reproduce your issue without the definition of your
models.
Is there a way you could provide them (ideally, a simplified version that
still reproduces the issue).

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:2>

Django

unread,
Dec 4, 2015, 7:31:52 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------

Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by stephanm):

I tried but I didn't get it :-(

Actually I use the following workaround:
{{{#!py
# at the beginning of the file before the first import:


if __name__ == "__main__":
import django
django.setup()

# now the imports ...


from myapp.models import MyModel1 # here is the exception
...
if __name__ == "__main__":

# skipped here ...
# import django
# django.setup()
# my code follows
}}}

I can live with this so you can close the ticket it if you like,
if I find a way to reproduce it in a simple "example" I will open it
again.

--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:3>

Django

unread,
Dec 4, 2015, 7:39:41 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => needsinfo


--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:4>

Django

unread,
Dec 4, 2015, 11:15:42 AM12/4/15
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by aaugustin):

This is the expected behavior. You need to setup Django before importing
models.

To avoid the extra `if __name__ == '__main__'` I think we should make
`django.setup()` idempotent.

I'll write to the DevelopersMailingList about this idea.

--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:5>

Django

unread,
Sep 4, 2016, 3:40:22 PM9/4/16
to django-...@googlegroups.com
#25864: AppRegistryNotReady exception since update from 1.8.7 to 1.9
-------------------------------+--------------------------------------
Reporter: stephanm | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by aaugustin):

I filed #27176 to improve the behavior in this area, but I'm not sure
that's the problem you were hitting.

--
Ticket URL: <https://code.djangoproject.com/ticket/25864#comment:6>

Reply all
Reply to author
Forward
0 new messages