0

Just started on Whoosh + Haystack.

I tested a test model which indexed fine and gave results. But indexing fails for some unknown reason on the second model (the important one)

Here is the model

class Sale(models.Model):
    brand = models.ForeignKey('Brand', related_name='sales_p')
    outlets = models.ManyToManyField('Outlet', null=True, blank=True, related_name='sales')
    child_brands = models.ManyToManyField('Brand', null=True, blank=True, related_name='sales_c')
    child_categories = models.ManyToManyField('Category', null=True, blank=True, related_name='sales_c')
#collecting subcategories for subcategory sale
    child_subcategories = models.ManyToManyField('SubCategory', null=True, blank=True,related_name='subcategory')

The search index for this is

class SaleIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    outlets = indexes.CharField(model_attr='outlets')
    child_brands = indexes.CharField(model_attr = 'child_brands')
    child_categories = indexes.CharField(model_attr = 'child_categories')
    child_subcategories = indexes.CharField(model_attr = 'child_subcategories')
    content_auto = indexes.CharField(model_attr='brand')

    def get_model(self):
        return Sale

    def index_queryset(self, using=None):
        return Sale.objects.all()

    def prep_childbrands(self, object):
        return [brand.name for brand in self.child_brands.all()]

No one else in the world seems to have faced this ever. Am new to programming in general. Is there something I am missing that is obvious?

Traceback if that helps:

Indexing 84 Sales
ERROR:root:Error updating website using default 
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 189, in handle_label
    self.update_backend(label, using)
  File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 234, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/usr/local/lib/python3.4/dist-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/usr/local/lib/python3.4/dist-packages/haystack/backends/whoosh_backend.py", line 191, in update
    doc = index.full_prepare(obj)
  File "/usr/local/lib/python3.4/dist-packages/haystack/indexes.py", line 207, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/usr/local/lib/python3.4/dist-packages/haystack/indexes.py", line 198, in prepare
    self.prepared_data[field.index_fieldname] = field.prepare(obj)
  File "/usr/local/lib/python3.4/dist-packages/haystack/fields.py", line 159, in prepare
    return self.convert(super(CharField, self).prepare(obj))
  File "/usr/local/lib/python3.4/dist-packages/haystack/fields.py", line 106, in prepare
    return current_object()
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 843, in __call__
    manager = getattr(self.model, kwargs.pop('manager'))
KeyError: 'manager'
  • After a lot of fiddling I can say that the error is only thrown when indexing the manytomany field entries. If I only try to index the foreignkey field (named brand above) then the indexing seems to proceed correctly. – Kunstructor Apr 23 '15 at 17:11

1 Answers1

0

There seems to be a bug in Haystack + Django 1.7 that is causing this error. This is also referenced in this other question which I had not noticed because of the Xapian mention (we are using Whoosh)

Django-haystack with xapian engine: can't execute update_index if model has ManyToManyField

Community
  • 1
  • 1