#8615: Changeset 8605 breaks model loading under unknown circumstances
--------------------------------------+-------------------------------------
Reporter: aeby | Owner: nobody
Status: new | Milestone: 1.0
Component: Admin interface | Version: SVN
Resolution: | Keywords: introspect models admin
validation
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
--------------------------------------+-------------------------------------
Changes (by mtredinnick):
* needs_better_patch: => 0
* summary: Changeset 8605 breaks model loading under unknow
circumstances => Changeset 8605 breaks model
loading under unknown circumstances
* needs_tests: => 0
* needs_docs: => 0
Comment:
From the traceback, it looks like you might be calling
`admin.site.register()` from inside the same file as you create the
models. For example, it looks like `atizo.platform.models.multilang_text`
creates the `MultiLangText` model and also registers it with the admin.
If that is correct, then don't do that. The admin registration doesn't
work in a number of subtle cases in that setup, since we reimport the
models from time to time.
This traceback looks like it exposing an existing problem in your code in
a more visible way than previously. Basically, you have a circular import
dependency going on because you're importing models by name explicitly. So
the platform.models.country` module is being imported and all the
consequences of that (including the `admin.sites.register()` call) are
leading to nested imports, culminating in an attempt to import `Country`
from `platform.models.country`, which is already being imported right at
the top (and isn't fully imported yet). The solution here is (a) don't
call `register()` in the models file, as already notes and (b) consider
not importing things directly from the module namespace. So, rather than
{{{
#!python
from platform.models.country import Country
}}}
you can write
{{{
#!python
from platform.models import country
# Then refer to it as country.Country
}}}
This is only strictly necessary when you have circular importing going on
and that's why it's being triggered here (because the admin app retrieval
for registering is triggering all the other imports). It's impossible to
work around having to periodically force all the model files to be
imported (there are lots of other bugs that we have had to work around and
`get_apps()` is pretty well debugged as a result). We can't even construct
a better error than the one Python gives you with the concluding line and
the traceback.
Please confirm if you do have the `admin.sites.register()` call in the
models file. If so, we can close this because it isn't a Django bug.
--
Ticket URL: <http://code.djangoproject.com/ticket/8615#comment:1>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---