[FIX] http_routing: revert b6ed34e1 and check _rewrite_len

Initial b6ed34e1 idea was to ensure that we always have
_rewrite_len and _routing_map defined. Unfortunately, this
is not correct since class attribute defined dynamically
are actually added in registry, and recomputed on each install.
More than that, the call si shared between multiple database
meaning that routing_map cache may be shared between multiple
database whcich is not correct.

After b6ed34e1, when installing discuss on a fresh database without
demo, all discuss routes will be unknown since None is already in
_routing_map and thus routing_map is not recomputed.

When routing_map is on the model class, in registry,
a new install will reset the class, remove the _routing_map attribute,
which will fix the problem.

Task #2117275

closes odoo/odoo#39640

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
Xavier-Do
2019-10-31 13:56:19 +00:00
parent 6bc1de5276
commit fe0da16a24
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ def url_for(url_from, lang_code=None, no_rewrite=False):
# don't try to match route if we know that no rewrite has been loaded.
routing = getattr(request, 'website_routing', None) # not modular, but not overridable
if not request.env['ir.http']._rewrite_len.get(routing):
if not getattr(request.env['ir.http'], '_rewrite_len', {}).get(routing):
no_rewrite = True
# avoid useless check for 1 char URL '/', '#', ... and absolute URL
+5 -3
View File
@@ -82,9 +82,6 @@ class IrHttp(models.AbstractModel):
# Routing map
#------------------------------------------------------
_routing_map = {}
_rewrite_len = {}
@classmethod
def _get_converters(cls):
return {'model': ModelConverter, 'models': ModelsConverter, 'int': SignedIntConverter}
@@ -253,6 +250,11 @@ class IrHttp(models.AbstractModel):
@classmethod
def routing_map(cls, key=None):
if not hasattr(cls, '_routing_map'):
cls._routing_map = {}
cls._rewrite_len = {}
if key not in cls._routing_map:
_logger.info("Generating routing map for key %s" % str(key))
installed = request.registry._init_modules | set(odoo.conf.server_wide_modules)