From 90fa25e44d644c0bb17de9cb745ab61dd5bcf0cd Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 26 Jul 2023 12:00:47 +0000 Subject: [PATCH] [FIX] website: avoid crash in search snippet when page has no url Since commit [1] (introduced in Odoo 15), when a published website page has no URL set, the search snippet would crash when typing something inside it. I am not sure why was the page url not required at the model level, this will be considered in master. Note that to create a page without a URL, the only flow is to create a new page in the backend. Indeed, the `write` is overridden to add a trailing `/`, and the frontend flows to create/write a page are also shielded against empty URL. Note that it's easy to create a page without a URL through legit flows. Depending on the Odoo version, there is always a way to reach a website page form view: either simply Website > Configuration > Pages or Site > Pages > Debug mode > Click on Bug icon in tree view > Click on page m2o. Step to reproduce: - Create a page with no URL (see above explanation how to do it) - Make sure it's publish (you can do it in the form view) - Drag & drop the Search snippet on a page - Type something in the search snippet -> TB [1]: https://github.com/odoo/odoo/commit/9f9c4bb7e40233e633f97c60fb00ae191e9077af#diff-77bd6b19c39e211959885024bcad914655ff84cfc10c16633687d014e50aa69aR69 Fixes https://github.com/odoo/odoo/issues/129728 closes odoo/odoo#129915 X-original-commit: f75ec6131eff9165b06d42d27a49dd756387f4a0 Signed-off-by: Benoit Socias (bso) Signed-off-by: Romain Derie (rde) --- addons/website/models/website.py | 1 + addons/website/models/website_page.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 435ccd3339e..7c3755d2cc3 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1248,6 +1248,7 @@ class Website(models.Model): if domain is None: domain = [] domain += self.get_current_website().website_domain() + domain = AND([domain, [('url', '!=', False)]]) pages = self.env['website.page'].sudo().search(domain, order=order, limit=limit) pages = pages._get_most_specific_pages() return pages diff --git a/addons/website/models/website_page.py b/addons/website/models/website_page.py index 71c2344a48a..c749b7179f6 100644 --- a/addons/website/models/website_page.py +++ b/addons/website/models/website_page.py @@ -96,7 +96,7 @@ class Page(models.Model): ids = [] previous_page = None # Iterate a single time on the whole list sorted on specific-website first. - for page in self.sorted(key=lambda p: (p.url, not p.website_id)): + for page in self.sorted(key=lambda p: (p.url or '', not p.website_id)): if not previous_page or page.url != previous_page.url: ids.append(page.id) previous_page = page