Weird haystack importerror (only in production)

Tags: django

Last thursday, 30 December, I updated a site at 16:30. Normally, updating a site at such an hour is a standing invitation to Murphy for wreaking havoc. But this was “just a small update”, so I was fine, right?

Boom. In my search_indexes.py, mod_wsgi complained:

Traceback (most recent call last):
    from haystack import indexes
ImportError: cannot import name indexes

What? It worked fine just before. Nothing related to any imports seemed to have changed. In any case not in the models.py, settings,py or that search_indexes.py. An obvious candidate for such an error is a circular import, but I couldn’t find any.

Today, I googled and found one page: a closed haystack issue. I couldn’t destill a clear reason for the failure from the discussion there, to be honest. Race condition, apparently? Perhaps a hidden circular dependency through 4 different levels? I don’t know.

Anyway, the temporary solution is to do haystack’s autodiscovering not in an search_sites.py, but to put the:

import haystack
haystack.autodiscover()

into your urls.py instead. I did it and that worked. But it doesn’t sit well with me. It seems to work and there’s a deadline next week, so I’ll leave it this way for now. But I sure hope someone replies on the ticket :-)

Well, it isn't a haystack, but at least it is grain :-)
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):