seo_og_type = 'article' giving error: date is not JSON serializable
ma00 opened this issue · 1 comments
ma00 commented
In ArticlePage model I added seo_og_type = 'article'
and I got a
TypeError
Object of type date is not JSON serializable
in template : wagtailseo/templates/wagtailseo/struct_data.html, error at line 10
8 {% if self.seo_og_type == "article" and settings.wagtailseo.SeoSettings.struct_meta %}
9 <script type="application/ld+json">
10 {{ self.seo_struct_article_json | safe }}
11 </script>
In the console I see this last lines:
python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable
ma00 commented
the problem should come from a date format conversion:
adding utils.serialize_date
in seo_struct_article_dict
at line 476 and 477 of wagtail-seo/wagtailseo/models.py
everything starts working again:
"datePublished": utils.serialize_date(self.seo_published_at),
"dateModified": utils.serialize_date(self.last_published_at),