plone / plone.app.multilingual

Plone Multilingual Content Add-on
https://pypi.org/project/plone.app.multilingual
18 stars 47 forks source link

Fix AttributeError when using multilingual switcher on neutral content. [1.x] #370

Closed mauritsvanrees closed 4 years ago

mauritsvanrees commented 4 years ago

I saw this in a client site, but see the same in a fresh Plone 4.3 site with plone.app.multilingual 1.x.

...
  Module zope.tales.tales, line 696, in evaluate
   - URL: /home/plone/production/eggs/plone.app.multilingual-1.2.3-py2.7.egg/plone/app/multilingual/browser/templates/not_translated_yet.pt
   - Line 34, Column 16
   - Expression: <PythonExpr (view.language_name(code))>
   - Names:
      {'args': (),
       'container': <PloneSite at /air>,
       'context': <PloneSite at /air>,
       'default': <object object at 0x7fb2b6428560>,
       'here': <PloneSite at /air>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x7fb28c25e368>,
       'request': <HTTPRequest, URL=http://127.0.01:8080/Plone/not_translated_yet/cd6052781ff44a31bc6c477c02546278>,
       'root': <Application at >,
       'template': <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x7fb29704fbd0>,
       'traverse_subpath': [],
       'user': <SpecialUser 'Anonymous User'>,
       'view': <Products.Five.metaclass.not_translated_yet object at 0x7fb28e3704d0>,
       'views': <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x7fb28c19ed50>}
  Module zope.tales.pythonexpr, line 59, in __call__
   - __traceback_info__: (view.language_name(code))
  Module <string>, line 1, in <module>
  Module plone.app.multilingual.browser.helper_views, line 252, in language_name
AttributeError: 'NoneType' object has no attribute 'get'

This PR fixes the immediate error, and results in a proper rendering of the not_yet_translated page. It is not pretty, but at least it is not an error page:

Screenshot 2020-03-16 at 16 42 56

Additionally, we should perhaps not show the multilingual switcher at all in neutral content. But this is ancient plone.app.multilingual 1.x, so let's not change it much.

BTW, the test buildout is pretty unmaintained and broken, which is not surprising: the last change was in June 2017. Locally it worked after copying a fresher bootstrap.py, commenting out most of the buildout, and adding version pins for the other multilingual packages. But I don't want to bother with that. bin/test at least runs, when you ignore the robot tests.

mauritsvanrees commented 4 years ago

Released as version 1.2.4.