From eb179429b6e466d52c90cd889f500729aa9ec198 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Tue, 22 Jun 2021 07:14:37 +0000 Subject: [PATCH] [FIX] website_blog: Prevent tags loading if no blogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Go to website app > configuration - Set the visibility of all the blog to Website A (So that it's not visible on Website B) - Go to the Blog menu of Website B - A traceback is triggered Problem: The `all_tags` function calls an SQL query to get the tags related to the website blog with a where condition based on the blog_id. But since there is no blog linked to the site. The request fails and an error is raised. Solution: Do not load the tags, if there is no blog for the website. Opw-2545315 closes odoo/odoo#72636 X-original-commit: 4d8fc86e4e6beb2171e3bebbabd532086d884d59 Signed-off-by: Jérémy Kersten (jke) Signed-off-by: Djamel Touati --- addons/website_blog/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 404f24906d6..52cddb8b0ad 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -116,7 +116,10 @@ class WebsiteBlog(http.Controller): step=self._blog_post_per_page, ) - all_tags = blogs.all_tags(join=True) if not blog else blogs.all_tags().get(blog.id, request.env['blog.tag']) + if not blogs: + all_tags = request.env['blog.tag'] + else: + all_tags = blogs.all_tags(join=True) if not blog else blogs.all_tags().get(blog.id, request.env['blog.tag']) tag_category = sorted(all_tags.mapped('category_id'), key=lambda category: category.name.upper()) other_tags = sorted(all_tags.filtered(lambda x: not x.category_id), key=lambda tag: tag.name.upper())