From e7b0ee301223c46f4ee71ac7c114a6d798e88721 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 28 Feb 2023 11:56:27 +0000 Subject: [PATCH] [FIX] website_blog: prevent params to be lost when only one blog With DB having only one blog (most common case, but we are used to test it with demo data where we have two), the query params are lost when accessing the blog controller without passing a blog. Eg, `/blog?search=hubble` will redirect to `/blog/travel-1` This is because the business code is doing an early redirect if we access the `/blog` URL without a blog post passed to it to redirect to that blog post URL directly (since there is only one), but that redirect is not passing the query parameters. The main impacted params are `state`, `order` and `search` but it's the same for all others. Step to reproduce (in later version): - Be sure to only have one blog - Drag & drop the search snippet in the homepage or anywhere - Make it search on blog only (through the snippet option) Type anything, it will not work and won't do the search. It will just redirect to the blog page. closes odoo/odoo#114107 X-original-commit: 41c27fd4912fb9f50ce5f31fff7c17c77b8530f7 Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Romain Derie (rde) --- addons/website_blog/controllers/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index dfa4e686220..d10d47c2aae 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -196,7 +196,8 @@ class WebsiteBlog(http.Controller): blogs = tools.lazy(lambda: Blog.search(request.website.website_domain(), order="create_date asc, id asc")) if not blog and len(blogs) == 1: - return request.redirect('/blog/%s' % slug(blogs[0]), code=302) + url = QueryURL('/blog/%s' % slug(blogs[0]), search=search, **opt)() + return request.redirect(url, code=302) date_begin, date_end = opt.get('date_begin'), opt.get('date_end')