Skip to content
Snippets Groups Projects
Commit dcac4cc0 authored by Olivier Dony's avatar Olivier Dony
Browse files

[FIX] website: slug: fallback to positive ID when slug appears to contain a missing negative ID

In some rare cases database records have negative IDs,
so the slug URL could look like /foo--20. This could
be mistaken for a slug ending with a `-` and a positive ID.
The latter is not supposed to happned as final hyphens
are stripped by slugify, but has been used in the past
and may be used in old links.
parent 12a9e379
No related branches found
No related tags found
No related merge requests found
......@@ -241,8 +241,13 @@ class ModelConverter(ir.ir_http.ModelConverter):
def to_python(self, value):
m = re.match(self.regex, value)
_uid = RequestUID(value=value, match=m, converter=self)
record_id = int(m.group(2))
if record_id < 0:
# limited support for negative IDs due to our slug pattern, assume abs() if not found
if not request.registry[self.model].exists(request.cr, _uid, [record_id]):
record_id = abs(record_id)
return request.registry[self.model].browse(
request.cr, _uid, int(m.group(2)), context=request.context)
request.cr, _uid, record_id, context=request.context)
def generate(self, cr, uid, query=None, args=None, context=None):
obj = request.registry[self.model]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment