coderedcorp / wagtail-seo

Search engine and social media optimization for Wagtail.
Other
66 stars 18 forks source link

seo_og_type = 'article' giving error: date is not JSON serializable #25

Closed ma00 closed 2 years ago

ma00 commented 3 years ago

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 3 years ago

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),