Files
odoo_source/addons/website/__init__.py
T
Julien Castiaux 814a34c3c9 [FIX] http_routing,website: missing request attribute during install
Steps to reproduce:

1) start from a clean database (http_routing should not be installed).
2) go to the app menu and install project (don't install via `-i`!!).
3) traceback: `request` has not attribute `is_frontend` while rendering
   a template.

The `is_frontend` attribute on request is set by the http_routing
module. At the moment the "install now" button is clicked, http_routing
was not installed so the `is_frontend` attribute was not set.

FF to the end of the installation: the registry is reloaded to include
the modules that have been installed, http_routing among them.

We are in a tricky situation: (1) there is a request, (2) http_routing
is installed and (3) the `is_frontend` attribute is missing from the
request.

This situation is illegal, when http_routing is installed, the
`is_frontend` attribut should always be set. In this work we reset the
missing attributes using sensitive default values via post-init hooks.

closes odoo/odoo#87684

Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-04-01 17:56:45 +02:00

41 lines
1.4 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
from . import wizard
import odoo
from odoo import api, SUPERUSER_ID
from odoo.http import request
from functools import partial
def uninstall_hook(cr, registry):
# Force remove ondelete='cascade' elements,
# This might be prevented by another ondelete='restrict' field
# TODO: This should be an Odoo generic fix, not a website specific one
env = api.Environment(cr, SUPERUSER_ID, {})
website_domain = [('website_id', '!=', False)]
env['ir.asset'].search(website_domain).unlink()
env['ir.ui.view'].search(website_domain).with_context(active_test=False, _force_unlink=True).unlink()
def rem_website_id_null(dbname):
db_registry = odoo.modules.registry.Registry.new(dbname)
with db_registry.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.model.fields'].search([
('name', '=', 'website_id'),
('model', '=', 'res.config.settings'),
]).unlink()
cr.postcommit.add(partial(rem_website_id_null, cr.dbname))
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.module.module'].update_theme_images()
if request:
env = env(context=request.default_context())
request.website_routing = env['website'].get_current_website().id