Tuesday, May 29, 2012

A signal, or equivalent, for when all apps are loaded?

I continue to struggle with occasional circular import problems
(caused by a combination of haystack, filebrowser, and a model which
both has a search_indexes.py and a model that has a filebrowser
field).

I had thought that I had patched the issue by importing haystack in my
root urlconf (the problem doesn't happen under the development server
because it "validates models" early, but the import order was
different in production). But: 1, I kept having to add "import
haystack" to my management commands; and 2, it still occasionally
fails on restart (a timing hazard of some kind).

It strikes me that one fix would be to defer haystack's scan of the
INSTALLED_APPS until all the apps have been loaded. But when is that?
I can ask django.db.models.loading.app_cache_ready(), but it will say
False when haystack (or its models.py, which it has, despite not
having any models) is being imported (since the list of apps being
cached can't be finished until haystack.models import has finished).
So when could I run it again? It would be nice to register for an
"apps are loaded" signal, but I don't see on in the docs, and there is
no evidence of sending one in django.db.models.loading.AppCache.

Is there a right way to get something called after all the models have
been imported? (Django 1.3)

Bill

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

No comments:

Post a Comment