From 391eb18eb2fce56582131c95001985ccec0899f1 Mon Sep 17 00:00:00 2001 From: Gorash Date: Mon, 28 Mar 2022 08:46:35 +0000 Subject: [PATCH] [IMP] website: slug method also works with lazy values Before this commit, the behavior is broken if using lazy values, the condition using isinstance does not work. It's best to use the slug as if given the correct value. Indeed, in odoo, we don't have any other object having `id` as attributes in addition to `seo_name` or `display_name` and not being a recordset and whose slug we want. If there is an error, it is imperative that we provided a tuple (from read). Part-of: odoo/odoo#88276 --- addons/http_routing/models/ir_http.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 62eea049830..0b37ce8c756 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -89,18 +89,18 @@ def slugify(s, max_length=0, path=False): def slug(value): - if isinstance(value, models.BaseModel): + try: if not value.id: raise ValueError("Cannot slug non-existent record %s" % value) # [(id, name)] = value.name_get() identifier, name = value.id, getattr(value, 'seo_name', False) or value.display_name - else: + except AttributeError: # assume name_search result tuple identifier, name = value slugname = slugify(name or '').strip().strip('-') if not slugname: return str(identifier) - return "%s-%d" % (slugname, identifier) + return f"{slugname}-{identifier}" # NOTE: as the pattern is used as it for the ModelConverter (ir_http.py), do not use any flags