[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) <bso@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2023-07-27 16:14:31 +02:00
parent 83903d0a90
commit 90fa25e44d
2 changed files with 2 additions and 1 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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