divio / aldryn-search

Haystack 2.0 search index for django CMS
Other
48 stars 78 forks source link

list index out of range error #20

Closed corpulent closed 10 years ago

corpulent commented 10 years ago

Hey guys, I keep getting this error. I can interact with elasticsearch through python shell without a problem, and update indexes. I can also connect to elasticsearch service through http. I think somehow aldryn_search is involved, which is why I created this issue here.

Here is my settings.py just in case http://pastebin.com/BbxDen35

(env)root@vagrant-ubuntu-trusty-64:/var/outermeasure/app# python manage.py update_index
/var/outermeasure/app/env/local/lib/python2.7/site-packages/app_data/fields.py:2: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

No handlers could be found for logger "elasticsearch"
Indexing 3 titles
ERROR:root:Error updating cms using default 
Traceback (most recent call last):
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 161, in update
    prepped_data = index.full_prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/indexes.py", line 204, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 40, in prepare
    request = self.get_request_instance(obj, current_language)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 47, in get_request_instance
    return get_request(language)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/helpers.py", line 54, in get_request
    request_factory = RequestFactory(HTTP_HOST=settings.ALLOWED_HOSTS[0])
IndexError: list index out of range
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 195, in handle
    return super(Command, self).handle(*items, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 385, in handle
    label_output = self.handle_label(label, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 161, in update
    prepped_data = index.full_prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/indexes.py", line 204, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 40, in prepare
    request = self.get_request_instance(obj, current_language)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 47, in get_request_instance
    return get_request(language)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/helpers.py", line 54, in get_request
    request_factory = RequestFactory(HTTP_HOST=settings.ALLOWED_HOSTS[0])
IndexError: list index out of range
czpython commented 10 years ago

@corpulent are you using django < 1.5 ? The problem is that to bypass django's exception on host headers, we have to pick a host from ALLOWED_HOSTS setting which in your case is empty, causing the IndexError. If you are using django < 1.5 then you can add localhost to ALLOWED_HOSTS

corpulent commented 10 years ago

@czpython I am using django 1.6.5 , my pip freeze http://pastebin.com/XtHV6ShG. I added localhost to ALLOWED_HOSTS, and now getting this error. NoReverseMatch: u'aldryn_blog' is not a registered namespace

(env)root@vagrant-ubuntu-trusty-64:/var/outermeasure/app# python manage.py update_index
/var/outermeasure/app/env/local/lib/python2.7/site-packages/app_data/fields.py:2: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

Indexing 0 titles
Indexing 1 posts
/var/outermeasure/app/env/local/lib/python2.7/site-packages/cms/admin/placeholderadmin.py:573: DeprecationWarning: Class FrontendEditableAdmin is deprecated and will be removed in 3.1. Instead, use FrontendEditableAdminMixin.
  "Instead, use FrontendEditableAdminMixin.", DeprecationWarning)

/var/outermeasure/app/env/local/lib/python2.7/site-packages/cms/admin/placeholderadmin.py:566: DeprecationWarning: Class PlaceholderAdmin is deprecated and will be removed in 3.1. Instead, combine PlaceholderAdminMixin with admin.ModelAdmin.
  "Instead, combine PlaceholderAdminMixin with admin.ModelAdmin.", DeprecationWarning)

/var/outermeasure/app/env/local/lib/python2.7/site-packages/cms/plugin_pool.py:156: DeprecationWarning: please rename the table "cmsplugin_latestentriesplugin" to "aldryn_blog_latestentriesplugin" in aldryn_blog
The compatibility code will be removed in 3.1
  bad_table_name, proper_table_name, model._meta.app_label), DeprecationWarning)

/var/outermeasure/app/env/local/lib/python2.7/site-packages/cms/plugin_pool.py:156: DeprecationWarning: please rename the table "cmsplugin_authorsplugin" to "aldryn_blog_authorsplugin" in aldryn_blog
The compatibility code will be removed in 3.1
  bad_table_name, proper_table_name, model._meta.app_label), DeprecationWarning)

ERROR:root:Error updating aldryn_blog using default 
Traceback (most recent call last):
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 161, in update
    prepped_data = index.full_prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/indexes.py", line 204, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 43, in prepare
    self.prepare_fields(obj, current_language, request)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 138, in prepare_fields
    self.prepared_data['url'] = self.get_url(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 119, in get_url
    return obj.get_absolute_url()
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 15, in _curried
    return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 1009, in get_absolute_url
    return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.model_name), func)(self, *args, **kwargs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_blog/models.py", line 186, in get_absolute_url
    return reverse('aldryn_blog:post-detail', kwargs=kwargs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 528, in reverse
    key)
NoReverseMatch: u'aldryn_blog' is not a registered namespace
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 195, in handle
    return super(Command, self).handle(*items, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 385, in handle
    label_output = self.handle_label(label, **options)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 161, in update
    prepped_data = index.full_prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/haystack/indexes.py", line 204, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 43, in prepare
    self.prepare_fields(obj, current_language, request)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 138, in prepare_fields
    self.prepared_data['url'] = self.get_url(obj)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_search/base.py", line 119, in get_url
    return obj.get_absolute_url()
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 15, in _curried
    return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 1009, in get_absolute_url
    return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.model_name), func)(self, *args, **kwargs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/aldryn_blog/models.py", line 186, in get_absolute_url
    return reverse('aldryn_blog:post-detail', kwargs=kwargs)
  File "/var/outermeasure/app/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 528, in reverse
    key)
django.core.urlresolvers.NoReverseMatch: u'aldryn_blog' is not a registered namespace
czpython commented 10 years ago

@corpulent ok then please make sure you change the ALLOWED_HOSTS to something correct domain when in production.

Regarding your error, please make sure you have added the aldryn blog apphook to a page.

corpulent commented 10 years ago

@czpython thank you very much! I should have tried that, so obvious...