From 277f51cbee3eb27abd17fa0df77ef53fb1c739b4 Mon Sep 17 00:00:00 2001 From: slava voloshyn Date: Fri, 18 Nov 2016 16:16:51 +0200 Subject: [PATCH] check that model_class present in index to prevent raising IndexNotFoundException --- celery_haystack/tasks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/celery_haystack/tasks.py b/celery_haystack/tasks.py index 09e54de..229d16b 100644 --- a/celery_haystack/tasks.py +++ b/celery_haystack/tasks.py @@ -72,9 +72,14 @@ def get_indexes(self, model_class, **kwargs): """ try: using_backends = connection_router.for_write(**{'models': [model_class]}) + index_found = False for using in using_backends: index_holder = connections[using].get_unified_index() - yield index_holder.get_index(model_class), using + if model_class in index_holder.get_indexed_models(): + index_found = True + yield index_holder.get_index(model_class), using + if not index_found: + raise IndexNotFoundException except IndexNotFoundException: raise ImproperlyConfigured("Couldn't find a SearchIndex for %s." % model_class)