nephila / djangocms-blog

django CMS blog application - Support for multilingual posts, placeholders, social network meta tags and configurable apphooks
https://djangocms-blog.readthedocs.io
BSD 3-Clause "New" or "Revised" License
403 stars 190 forks source link

post.get_absolute_url fails with permalink structure set to category when article isn’t assigned to a category #667

Open MacLake opened 3 years ago

MacLake commented 3 years ago

Description

Changing the permalink structure in the blog settings to category leads to an AttributeError caused by {{ post.get_absolute_url }} in templates/djangocms_blog/includes/blog_item.html

Steps to reproduce

  1. Create at least one blog article without choosing a category
  2. Select permalink structure “category” in the blog settings
  3. Rendering overview pages like the post list or plug-in “Latest Blog Articles” will fail.

Versions

Python 3.7 and 3.9, Django 3.0.11, djangocms-blog 1.2.3

Expected behaviour

Even if it sounds logical that blog post must have a category assigned if you want to have URLs containing the category, the app should be so forgiving and not crash in this case but rather using a default category in the URL

Actual behaviour

AttributeError at /de/news/

'NoneType' object has no attribute 'safe_translation_getter'

Error during template rendering

In template /home/jens/develop/djangocms/phi/templates/djangocms_blog/includes/blog_item.html, error at line 26
'NoneType' object has no attribute 'safe_translation_getter'

in

<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>