Django django-haystack cannot import CategoryBase from django-categories on the first run -
i have custom category model extends categorybase
in django-categories.
when put haystack index , restart server, on first run complains cannot import name categorybase
categorybase
cannot imported categories.base
if refresh page again site runs fine , search result returns correct information. seems because of order of imports.
i looked @ stacktrace , found out error originating admin.autodiscover
inside urls.py imports looks in urls.py
from django.conf.urls import patterns, include, url django.contrib import admin admin.autodiscover() django.conf import settings django.contrib.staticfiles.urls import staticfiles_urlpatterns django.views.generic import templateview django.contrib.sitemaps import genericsitemap galleries.models import gallery events.models import event django.contrib.auth.views import login, logout dajaxice.core import dajaxice_autodiscover, dajaxice_config core.models import staticpagesitemap articles.models import articlesitemap, issuesitemap dajaxice_autodiscover()
i have tried moving autodiscover after imports below:
from django.conf.urls import patterns, include, url django.contrib import admin django.conf import settings django.contrib.staticfiles.urls import staticfiles_urlpatterns django.views.generic import templateview django.contrib.sitemaps import genericsitemap galleries.models import gallery events.models import event django.contrib.auth.views import login, logout dajaxice.core import dajaxice_autodiscover, dajaxice_config core.models import staticpagesitemap articles.models import articlesitemap, issuesitemap admin.autodiscover() dajaxice_autodiscover()
while error has gone away on first run search not return result on categories.
here stacktrace:
django version: 1.5 python version: 2.7.3 installed applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.comments', 'django.contrib.sites', 'django.contrib.markup', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sitemaps', 'django.contrib.sessions', 'django.contrib.admin', 'djcelery', 'filebrowser', 'compressor', 'south', 'taggit', 'categories', 'categories.editor', 'core', 'articles', 'newsletters', 'galleries', 'events', 'haystack', 'dajaxice', 'zencode', 'videos', 'directory', 'dps_payment', 'home', 'taggit_autosuggest', 'captcha', 'search', 'media_board'] installed middleware: ('django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware') traceback: file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 92. response = middleware_method(request) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/middleware/common.py" in process_request 69. if (not urlresolvers.is_valid_path(request.path_info, urlconf) , file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in is_valid_path 551. resolve(path, urlconf) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve 440. return get_resolver(urlconf).resolve(path) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve 319. pattern in self.url_patterns: file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns 347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module 342. self._urlconf_module = import_module(self.urlconf_name) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) file "/srv/www/weddings/weddings_advanced/weddings/urls.py" in <module> 3. admin.autodiscover() file "/srv/www/weddings/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in autodiscover 29. import_module('%s.admin' % app) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/contrib/auth/admin.py" in <module> 172. admin.site.register(group, groupadmin) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in register 98. validate(admin_class, model) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/contrib/admin/validation.py" in validate 22. models.get_apps() file "/srv/www/weddings/local/lib/python2.7/site-packages/django/db/models/loading.py" in get_apps 134. self._populate() file "/srv/www/weddings/local/lib/python2.7/site-packages/django/db/models/loading.py" in _populate 75. self.load_app(app_name) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/db/models/loading.py" in load_app 96. models = import_module('.models', app_name) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) file "/srv/www/weddings/weddings_advanced/videos/models.py" in <module> 9. categories.models import category file "/srv/www/weddings/local/lib/python2.7/site-packages/categories/models.py" in <module> 13. .base import categorybase file "/srv/www/weddings/local/lib/python2.7/site-packages/categories/base.py" in <module> 32. class categorybase(mpttmodel): file "/srv/www/weddings/local/lib/python2.7/site-packages/categories/base.py" in categorybase 41. verbose_name=_('parent')) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/translation/__init__.py" in ugettext 71. return _trans.ugettext(message) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py" in ugettext 276. return do_translate(message, 'ugettext') file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py" in do_translate 258. _default = translation(settings.language_code) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py" in translation 172. default_translation = _fetch(settings.language_code) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py" in _fetch 154. app = import_module(appname) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) file "/srv/www/weddings/local/lib/python2.7/site-packages/haystack/__init__.py" in <module> 154. handle_registrations() file "/srv/www/weddings/local/lib/python2.7/site-packages/haystack/__init__.py" in handle_registrations 151. search_sites_conf = importlib.import_module(settings.haystack_siteconf) file "/srv/www/weddings/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) file "/srv/www/weddings/weddings_advanced/search/search_sites.py" in <module> 8. directory.models import listing, category directorycategory file "/srv/www/weddings/weddings_advanced/directory/models.py" in <module> 21. categories.base import categorybase exception type: importerror @ /directory/listing/new-listing-gift exception value: cannot import name categorybase
finally managed fix it!!!!
root cause in from categories.models import category
in videos app, app model importing category extends categorybase, , it's causing circular reference, fix it, in models.py of videos app, change direct import lazy import below:
categories = models.manytomanyfield('categories.category', null=true, blank=true)
update:
above fix worked briefly , got other circular import problems on other models, fixed upgrading haystack v2.1.0
Comments
Post a Comment