From 2e9c6f22d57776806227b11157e32a4aa34be01c Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Thu, 24 Feb 2022 15:35:22 +0000 Subject: [PATCH] [FIX] website: nonexisting record id in URL =>404 Install the website_sale and open '/shop/whatever-9999' in your browser, the response is a 500 Internal Error instead of a 404 Page not Found. Because `request.endpoint` has been murdered by the httpocalypse, we must re-match to get the endpoint later used to re-build the URL. When an URL contains a record-id but that record does not exists, matching the URL will raise a `odoo.exceptions.MissingError`. Part-of: odoo/odoo#85340 --- addons/website/models/website.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 1fe1d3c997d..09b28fb4f79 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -20,7 +20,7 @@ from odoo.addons.website.models.ir_http import sitemap_qs2dom from odoo.addons.website.tools import similarity_score, text_from_html from odoo.addons.portal.controllers.portal import pager from odoo.addons.iap.tools import iap_tools -from odoo.exceptions import UserError, AccessError +from odoo.exceptions import UserError, AccessError, MissingError from odoo.http import request from odoo.modules.module import get_resource_path, get_manifest from odoo.osv.expression import AND, OR, FALSE_DOMAIN, get_unaccent_wrapper @@ -1310,7 +1310,7 @@ class Website(models.Model): router = http.root.get_db_router(request.db).bind('') path = router.build(rule.endpoint, args) - except (NotFound, AccessError): + except (NotFound, AccessError, MissingError): # The build method returns a quoted URL so convert in this case for consistency. path = urls.url_quote_plus(request.httprequest.path, safe='/') lang_path = f'/{lang.url_code}' if lang != self.default_lang_id else ''