[FIX] http_routing: compat for werkzeug 2.2.x
The path matching logic got reimplemented in werkzeug 2.2[^1] and the new router is no more compatible with regexp groups[^2]. Our custom converter for slugged-records in urls (`'/partner/agrolait-5'` => `5`) has been adapted to match the route using non-capturing groups. It still extracts the slug/id pair using the groups-capturing regexp. [^1]: https://github.com/pallets/werkzeug/pull/2433 [^2]: https://github.com/pallets/werkzeug/pull/2519 Part-of: odoo/odoo#112298
This commit is contained in:
committed by
Christophe Monniez
parent
442c776cb6
commit
01b30c2cbf
@@ -99,8 +99,9 @@ def slug(value):
|
||||
return f"{slugname}-{identifier}"
|
||||
|
||||
|
||||
# NOTE: as the pattern is used as it for the ModelConverter (ir_http.py), do not use any flags
|
||||
# NOTE: the second pattern is used for the ModelConverter, do not use nor flags nor groups
|
||||
_UNSLUG_RE = re.compile(r'(?:(\w{1,2}|\w[A-Za-z0-9-_]+?\w)-)?(-?\d+)(?=$|\/|#|\?)')
|
||||
_UNSLUG_ROUTE_PATTERN = r'(?:(?:\w{1,2}|\w[A-Za-z0-9-_]+?\w)-)?(?:-?\d+)(?=$|\/|#|\?)'
|
||||
|
||||
|
||||
def unslug(s):
|
||||
@@ -248,13 +249,13 @@ class ModelConverter(ir_http.ModelConverter):
|
||||
def __init__(self, url_map, model=False, domain='[]'):
|
||||
super(ModelConverter, self).__init__(url_map, model)
|
||||
self.domain = domain
|
||||
self.regex = _UNSLUG_RE.pattern
|
||||
self.regex = _UNSLUG_ROUTE_PATTERN
|
||||
|
||||
def to_url(self, value):
|
||||
return slug(value)
|
||||
|
||||
def to_python(self, value):
|
||||
matching = re.match(self.regex, value)
|
||||
matching = _UNSLUG_RE.match(value)
|
||||
_uid = RequestUID(value=value, match=matching, converter=self)
|
||||
record_id = int(matching.group(2))
|
||||
env = api.Environment(request.cr, _uid, request.context)
|
||||
|
||||
Reference in New Issue
Block a user