[Django]-Django Haystack + Elasticsearch strange intermittent bug

0👍

You’re probably using threaded workers in your app server and django-haystack is not thread-safe by default. See the warning here:

Warning

The standard SearchView is not thread-safe. Use the
search_view_factory function, which returns thread-safe instances of
SearchView.

One solution is to not use threaded workers in the app server, e.g. in Gunicorn, start the app server with --workers X instead of --workers X --threads Y. But that may impact your app performance.

An alternative solution is to coerce SearchQuerySet to use the default connection, as suggested here, but simplified as follows in your code:

topics_list = SearchQuerySet(using='default').filter(**filter).models(Topic)
👤Chris

Leave a comment