forked from OCA/rest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastapi_dispatcher.py
More file actions
34 lines (26 loc) · 1.06 KB
/
fastapi_dispatcher.py
File metadata and controls
34 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright 2023 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
from contextlib import contextmanager
from odoo.http import _dispatchers
from odoo.addons.extendable.registry import _extendable_registries_database
from odoo.addons.fastapi.fastapi_dispatcher import (
FastApiDispatcher as BaseFastApiDispatcher,
)
from extendable import context
# Inherit from last registered fastapi dispatcher
# This handles multiple overload of dispatchers
class FastApiDispatcher(_dispatchers.get("fastapi", BaseFastApiDispatcher)):
routing_type = "fastapi"
def dispatch(self, endpoint, args):
with self._manage_extendable_context():
return super().dispatch(endpoint, args)
@contextmanager
def _manage_extendable_context(self):
env = self.request.env
registry = _extendable_registries_database.get(env.cr.dbname, {})
token = context.extendable_registry.set(registry)
try:
response = yield
finally:
context.extendable_registry.reset(token)
return response