mardi 19 juin 2018

Django : Mezzanine "title_fr" not in list

I'm using Mezzanine, and doing some unit tests on.

self.department_page = DepartmentPage.objects.create(title="title department",content="my dep content", publish_date=datetime.today(),department=self.department, status=CONTENT_STATUS_PUBLISHED)

Above is part of my setUp, and here is the DepartmentPage model.

class DepartmentPage(Page, SubTitled, RichText):
    """(Department description)"""

    department = models.ForeignKey('Department', verbose_name=_('department'), related_name="pages", blank=True, null=True, on_delete=models.SET_NULL)
    weaving_css_class = models.CharField(_('background pattern'), choices=PATTERN_CHOICES, max_length=64, blank=True)

    class Meta:
        verbose_name = _('department page')

Here is my unit test :

response = self.client.get("/title-department/")

And, strangely, i've this error :

Traceback (most recent call last):
  File "/srv/lib/mezzanine-organization/organization/network/test/tests.py", line 165, in test_department_display_for_everyone
    response = self.client.get("/title-department/")
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 503, in get
    **extra)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 304, in get
    return self.generic('GET', path, secure=secure, **r)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 380, in generic
    return self.request(**r)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 449, in request
    response = self.handler(environ)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 123, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 296, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/srv/lib/mezzanine/mezzanine/core/views.py", line 220, in server_error
    return HttpResponseServerError(t.render(context, request))
  File "/usr/local/lib/python3.6/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/usr/local/lib/python3.6/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 173, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.6/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/defaulttags.py", line 441, in render
    return strip_spaces_between_tags(self.nodelist.render(context).strip())
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/srv/lib/mezzanine/mezzanine/template/__init__.py", line 68, in render
    return tag_func(context, token)
  File "/srv/lib/mezzanine/mezzanine/pages/templatetags/pages_tags.py", line 86, in page_menu
    for page in published.order_by("_order"):
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 258, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 67, in __iter__
    related_populators = get_related_populators(klass_info, select, db)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1728, in get_related_populators
    rel_cls = RelatedPopulator(rel_klass_info, select, db)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1672, in __init__
    init_pos = model_init_attnames.index(field.attname)
ValueError: 'title_fr' is not in list

Looking through this error, you can see the problem comes from pages_tags.py.

rel = [m.__name__.lower()
               for m in Page.get_content_models()
               if not m._meta.proxy]
Page.objects.published(for_user=user).select_related(*rel)
for page in published.order_by("_order"):

But this code is part of Mezzanine module, and i really have some difficulties to understand it :/.

If you have some ideas of where the problem can come from, would be appreciated !

Thanks in advance.

PS : Page, SubTitled models are on github

Aucun commentaire:

Enregistrer un commentaire