Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError when using Haystack 2.0.0 with Django 1.5 and Gunicorn WSGI

I use django-haystack 2.0.0 to index my site, and it has been working great until I upgraded to Django 1.5 and started using the WSGI interface. If I just use the django_gunicorn command it works great, but the Django documentation "highly recommends" I use the gunicorn command.

When I start my site with the gunicorn command, Haystack throws the following error on any page load:

ImportError: cannot import name signals

I have no problems importing signals from the Django or Python shells. I use virtualenv and install all packages locally inside that environment. My wsgi.py file looks just like the default one in the django admin, except that I add the local path to the python path as such:

path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])
if path not in sys.path:
    sys.path.append(path)`

Any help you could provide would be very appreciated, thank you!

like image 467
Tom Avatar asked Mar 24 '23 15:03

Tom


1 Answers

I don't use gunicorn, but I had the same problem when I used the HAYSTACK_SIGNAL_PROCESSOR setting to point to a custom class that I wrote. That class imported one of my models, which eventually propagated up the import chain, to import my settings module, thus causing a circular import.

When using a setting such as HAYSTACK_SIGNAL_PROCESSOR that points to a class, make sure that class standsalone, and doesn't import either directly or indirectly the Django settings file.

like image 182
Steve Bradshaw Avatar answered Mar 26 '23 04:03

Steve Bradshaw