Saleor: Elasticsearch URL not configured: InvalidSearchBackendError

Created on 7 Nov 2017  路  12Comments  路  Source: mirumee/saleor

hi
i keep getting an error in search backends
Exception Type: InvalidSearchBackendError
Exception Value: Could not find backend 'default': No module named 'default'
and i don't know how to fix it!

bug

Most helpful comment

Ok, that's a bug. Search should be disabled. Thank you for getting to the bottom of this.

All 12 comments

What's your SEARCH_BACKENDS setting?

SEARCH_BACKENDS = {
'default': {
'BACKEND': 'saleor.search.backends.elasticsearch5',
'URLS': [ES_URL],
'INDEX': os.environ.get('ELASTICSEARCH_INDEX_NAME', 'storefront'),
'TIMEOUT': 5,
'AUTO_UPDATE': True},
'dashboard': {
'BACKEND': 'saleor.search.backends.dashboard',
'URLS': [ES_URL],
'INDEX': os.environ.get('ELASTICSEARCH_INDEX_NAME', 'storefront'),
'TIMEOUT': 5,
'AUTO_UPDATE': False}
}

Are you sure it's actually set? The exception seems to indicate that the setting is empty or at least missing the default key?

yes i'm sure. does this method somehow use uwsgi package? because that package is missing from my packages and unfortunately i can't install it! i'm using windows

No, it shouldn't touch uwsgi. I'd suggest starting with checking the value returned by get_search_backend_config in saleor/search/backends/__init__.py.

get_search_backend_config returned an empty dict 馃槰

Unless you've modified this code in a way, by default it returns the above setting. This does not seem right. Let me know if you determine why it ends up being empty or if you have any additional hints I could use to direct you to other parts of code.

in setting.py:
ES_URL = ELASTICSEARCH_URL or SEARCHBOX_URL or BONSAI_URL or ''
if ES_URL
and if i change ES_URL to True, get_search_backend_config return the right dict.
i think the problem is one of these ELASTICSEARCH_URL or SEARCHBOX_URL or BONSAI_URL is not set somehow. can i ask what are these urls and how they initialized?

Hmm, if neither is set then search should disable itself and you should not be getting this error. What action are you attempting when you get this error? Could you paste the full stack trace from the error page?

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/search/?q=sample

Django Version: 1.11.5
Python Version: 3.6.1
Installed Applications:
['storages',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sitemaps',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.auth',
'django.contrib.postgres',
'django.forms',
'saleor.userprofile',
'saleor.discount',
'saleor.product',
'saleor.cart',
'saleor.checkout',
'saleor.core',
'saleor.graphql',
'saleor.order',
'saleor.dashboard',
'saleor.shipping',
'saleor.search',
'saleor.site',
'saleor.data_feeds',
'versatileimagefield',
'babeldjango',
'bootstrap3',
'django_prices',
'django_prices_openexchangerates',
'graphene_django',
'mptt',
'payments',
'webpack_loader',
'social_django',
'django_countries',
'django_filters',
'django_celery_results']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'babeldjango.middleware.LocaleMiddleware',
'saleor.core.middleware.DiscountMiddleware',
'saleor.core.middleware.GoogleAnalytics',
'saleor.core.middleware.CountryMiddleware',
'saleor.core.middleware.CurrencyMiddleware',
'saleor.core.middleware.ClearSiteCacheMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware']

Traceback:

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\module_loading.py" in import_string

  1. module_path, class_name = dotted_path.rsplit('.', 1)

During handling of the above exception (not enough values to unpack (expected 2, got 1)), another exception occurred:

File "E:\Programming\Python\saleor\saleor\search\backends__init__.py" in import_backend

  1. return import_string(dotted_path)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\module_loading.py" in import_string

  1. six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\six.py" in reraise

  1. raise value.with_traceback(tb)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\module_loading.py" in import_string

  1. module_path, class_name = dotted_path.rsplit('.', 1)

During handling of the above exception (default doesn't look like a module path), another exception occurred:

File "E:\Programming\Python\saleor\saleor\search\backends__init__.py" in get_search_backend

  1. import_backend(backend)

File "E:\Programming\Python\saleor\saleor\search\backends__init__.py" in import_backend

  1. six.reraise(ImportError, e, sys.exc_info()[2])

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\six.py" in reraise

  1. raise value.with_traceback(tb)

File "E:\Programming\Python\saleor\saleor\search\backends__init__.py" in import_backend

  1. return import_string(dotted_path)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\module_loading.py" in import_string

  1. six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\six.py" in reraise

  1. raise value.with_traceback(tb)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\module_loading.py" in import_string

  1. module_path, class_name = dotted_path.rsplit('.', 1)

During handling of the above exception (No module named 'default'), another exception occurred:

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner

  1. response = get_response(request)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response

  1. response = self._get_response(request)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "C:\Users\MehrdadAppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = wrapped_callback(request, callback_args, *callback_kwargs)

File "E:\Programming\Python\saleor\saleor\search\views.py" in search

  1. results = form.search(model_or_queryset=visible_products)

File "E:\Programming\Python\saleor\saleor\search\forms.py" in search

  1. backend = get_search_backend('default')

File "E:\Programming\Python\saleor\saleor\search\backends__init__.py" in get_search_backend

  1. backend, e))

Exception Type: InvalidSearchBackendError at /search/
Exception Value: Could not find backend 'default': No module named 'default'

Ok, that's a bug. Search should be disabled. Thank you for getting to the bottom of this.

@salwator This seems related to your current work on the search backends. We should add some safeguards so search is not reachable when not configured.

Was this page helpful?
0 / 5 - 0 ratings