I've run into this problem when using dbsettings / django-values in my
project, but the source of the problem actually lies deeper.

There's a core class django.db.models.loading.AppCache which populates
the list of project apps and models. It works pretty well unless a
specific set of conditions is met.

1. The server is under mod_python (or at least not "manage.py
runserver")
2. The project's url.py imports myapp.models
3. In myapp.models, there's a code which uses db API, like: foos =
Foo.objects.all()

In this case, "myapp" doesn't get properly registered within AppCache.
One of the visible effects is that myapp's model aren't shown in
Django Admin anymore.

The code which actually breaks is in method AppCache.load_app():

mod = __import__(app_name, {}, {}, ['models'])
self.nesting_level -= 1
if not hasattr(mod, 'models'):

The condition is never met since myapps.models starts being imported
before _populate() is called, so even can_postpone / self.postponed
hack doesn't help.

I temporary fixed the problem by populating the cache manually in my
urls.py:
import django.db.models.loading
django.db.models.loading.cache._populate()

Obviously, this is ugly and should be fixed at core level.

Any comments/suggestions?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to