coderedcorp/wagtail-seo

'NoneType' object has no attribute 'site_name' on translation pages

nl-emmanuellodovice opened this issue · 4 comments

When following the approach for internationalization in https://docs.wagtail.org/en/stable/advanced_topics/i18n.html , when you to visit a translation of your page you get this error because of wagtail-seo

 File "/lib/python3.8/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/lib/python3.8/site-packages/django/template/base.py", line 837, in _resolve_lookup
    current = getattr(current, bit)
  File "/lib/python3.8/site-packages/wagtailseo/models.py", line 313, in seo_pagetitle
    self.title, settings.get("WAGTAILSEO_SEP"), self.seo_sitename
  File "/lib/python3.8/site-packages/wagtailseo/models.py", line 297, in seo_sitename
    return self.get_site().site_name

Exception Type: AttributeError at /
Exception Value: 'NoneType' object has no attribute 'site_name'

Do you think this change will help your issue? #33

As a quick fix for your project, could you try overriding seo_sitename() on your page model, to return a hard-coded string?

Thanks, that I think solves my problem.

Great. I would still like to get to the root of the problem, ideally this should work out-of-box with translated sites as well.

Fix for the symptoms is in 1.0.1 and 2.0.1. Not sure what would cause translated pages to not have a site though! Please re-open if you have more info.