Skip to content
Snippets Groups Projects
Commit 62ee506a authored by Jeremy Kersten's avatar Jeremy Kersten
Browse files

[FIX] website: handle RequestUID case in slug

Before this commit, a 308 on a route with a modelconverter for a model
that have a seo_name field will crash with an exception:
Cannot iterate on RequestUID

Another simplest solution was to use a with_user(SUPERUSER_ID) but in this case
it bypass the security set and display the name of the record even if not yet
published.

How to reproduce:

Create a 308 from /shop/<product> to /mag/<product>
Unpublish product 10
Try to access /shop/product-10

You have an unmanaged '500 internal error"
because slug_matching -> build -> to_url -> slug with a record with Requestuid
as env._uid.
parent 13364672
Branches
Tags
No related merge requests found
......@@ -255,7 +255,7 @@ class ModelConverter(ModelConverter):
# limited support for negative IDs due to our slug pattern, assume abs() if not found
if not env[self.model].browse(record_id).exists():
record_id = abs(record_id)
return env[self.model].browse(record_id)
return env[self.model].with_context(_converter_value=value).browse(record_id)
class IrHttp(models.AbstractModel):
......
......@@ -19,7 +19,6 @@ from odoo import registry, SUPERUSER_ID
from odoo.http import request
from odoo.tools.safe_eval import safe_eval
from odoo.osv.expression import FALSE_DOMAIN
from odoo.addons.http_routing.models.ir_http import ModelConverter, _guess_mimetype
from odoo.addons.portal.controllers.portal import _build_url_w_params
......@@ -75,7 +74,7 @@ class Http(models.AbstractModel):
def _slug_matching(cls, adapter, endpoint, **kw):
for arg in kw:
if isinstance(kw[arg], models.BaseModel):
kw[arg] = kw[arg].sudo()
kw[arg] = kw[arg].with_context(slug_matching=True)
qs = request.httprequest.query_string.decode('utf-8')
try:
return adapter.build(endpoint, kw) + (qs and '?%s' % qs or '')
......@@ -423,6 +422,11 @@ class Http(models.AbstractModel):
class ModelConverter(ModelConverter):
def to_url(self, value):
if value.env.context.get('slug_matching'):
return value.env.context.get('_converter_value', str(value.id))
return super().to_url(value)
def generate(self, uid, dom=None, args=None):
Model = request.env[self.model].with_user(uid)
# Allow to current_website_id directly in route domain
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment