rest-framework
rest-framework copied to clipboard
Patched version Root.get_request was not called for the very first HTTP request
There is an issue regarding the very first HTTP call after odoo restart. It is always handled by the original get_request handler, instead the one Rest Framework patched as below.
def get_request(self, httprequest):
db = httprequest.session.db
if db:
# on the very first request processed by a worker,
# registry is not loaded yet
# so we enforce its loading here to make sure that
# _rest_services_databases is not empty
odoo.registry(db)
service_registry = _rest_services_databases.get(db)
if service_registry:
for root_path in service_registry:
if httprequest.path.startswith(root_path):
return HttpRestRequest(httprequest)
return ori_get_request(self, httprequest)
Root.get_request = get_request
For the debug message, the Root.get_request was indeed patched(2021-05-08 17:51:45,967) after base_rest loaded. However the next HTTP request was still handled by the original odoo handler(2021-05-08 17:51:46,191)
2021-05-08 17:51:45,904 42021 DEBUG gateway odoo.modules.loading: loading module datamodel (2/13)
2021-05-08 17:51:45,918 42021 DEBUG gateway odoo.modules.loading: loading module component (3/13)
2021-05-08 17:51:45,926 42021 DEBUG gateway odoo.modules.loading: loading module web (4/13)
2021-05-08 17:51:45,930 42021 DEBUG gateway odoo.modules.loading: loading module base_import (5/13)
2021-05-08 17:51:45,950 42021 DEBUG gateway odoo.modules.loading: loading module base_rest (6/13)
2021-05-08 17:51:45,967 42021 DEBUG gateway odoo.addons.base_rest.http: --------Patching Root.get_request
2021-05-08 17:51:45,967 42021 DEBUG gateway odoo.modules.loading: loading module odoo_referral (7/13)
2021-05-08 17:51:45,970 42021 DEBUG gateway odoo.modules.loading: loading module web_diagram (8/13)
2021-05-08 17:51:45,972 42021 DEBUG gateway odoo.modules.loading: loading module web_editor (9/13)
2021-05-08 17:51:45,990 42021 DEBUG gateway odoo.modules.loading: loading module web_kanban_gauge (10/13)
2021-05-08 17:51:45,991 42021 DEBUG gateway odoo.modules.loading: loading module web_tour (11/13)
2021-05-08 17:51:45,994 42021 DEBUG gateway odoo.modules.loading: loading module base_rest_datamodel (12/13)
2021-05-08 17:51:45,998 42021 DEBUG gateway odoo.modules.loading: loading module gateway (13/13)
2021-05-08 17:51:46,019 42021 INFO gateway odoo.modules.loading: 13 modules loaded in 0.11s, 0 queries
2021-05-08 17:51:46,143 42021 INFO gateway odoo.modules.loading: Modules loaded.
2021-05-08 17:51:46,171 42021 DEBUG gateway odoo.modules.registry: Multiprocess signaling check: [Registry - 9 -> 9] [Cache - 2 -> 2]
2021-05-08 17:51:46,171 42021 INFO gateway odoo.addons.base.models.ir_http: Generating routing map for key None
2021-05-08 17:51:46,191 42021 INFO gateway werkzeug: 127.0.0.1 - - [08/May/2021 17:51:46] "GET /kkk HTTP/1.1" 404 - 23 0.020 0.301
2021-05-08 17:51:46,287 42021 DEBUG ? odoo.addons.base_rest.http: DB is :gateway
2021-05-08 17:51:46,288 42021 DEBUG gateway odoo.modules.registry: Multiprocess signaling check: [Registry - 9 -> 9] [Cache - 2 -> 2]
2021-05-08 17:51:46,290 42021 INFO gateway werkzeug: 127.0.0.1 - - [08/May/2021 17:51:46] "GET /favicon.ico HTTP/1.1" 404 - 2 0.001 0.003
2021-05-08 17:52:28,841 42021 DEBUG ? odoo.service.server: cron0 polling for jobs
2021-05-08 17:52:29,840 42021 DEBUG ? odoo.service.server: cron1 polling for jobs
2021-05-08 17:52:33,824 42021 DEBUG ? odoo.addons.base_rest.http: DB is :gateway
2021-05-08 17:52:33,826 42021 DEBUG gateway odoo.modules.registry: Multiprocess signaling check: [Registry - 9 -> 9] [Cache - 2 -> 2]
2021-05-08 17:52:33,830 42021 INFO gateway werkzeug: 127.0.0.1 - - [08/May/2021 17:52:33] "GET /kkk HTTP/1.1" 404 - 2 0.001 0.006
As a result, the very first call will be 500 if it's a REST API call.
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.
Hi,
I was just wondering if anyone else is experiencing this? On cloud hosting (no guarantee that the server is running) this has a serious impact.
Regards
This patch work like a charm ...!
You need to load base_rest at odoo start. Because, this enforce the loading of the registry in the get_request(). So we can use base_rest as server_wide_module()
Here odoo conf example :
[options]
# ex: for Odoo 14.0
server_wide_modules=base,web,base_rest
# ...
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.
Should be solved by https://github.com/OCA/rest-framework/pull/276