Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def dispatch(self, endpoint, args):
# don't parse the httprequest let starlette parse the stream
self.request.params = {} # dict(self.request.get_http_params(), **args)
environ = self._get_environ()
root_path = "/" + environ["PATH_INFO"].split("/")[1]
path = environ["PATH_INFO"]
# TODO store the env into contextvar to be used by the odoo_env
# depends method
with fastapi_app_pool.get_app(env=request.env, root_path=root_path) as app:
uid = request.env["fastapi.endpoint"].sudo().get_uid(root_path)
with fastapi_app_pool.get_app(env=request.env, root_path=path) as app:
uid = request.env["fastapi.endpoint"].sudo().get_uid(path)
data = BytesIO()
with self._manage_odoo_env(uid):
for r in app(environ, self._make_response):
Expand Down
17 changes: 12 additions & 5 deletions fastapi/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,15 @@ def _reset_app_cache_marker(self):
"""

@api.model
def get_app(self, root_path):
record = self.search([("root_path", "=", root_path)])
@tools.ormcache("path")
def get_endpoint(self, path):
root_path = "/" + path.split("/")[1]
endpoint = self.search([("root_path", "=", root_path)])[:1] or False
return endpoint

@api.model
def get_app(self, path):
record = self.get_endpoint(path)
if not record:
return None
app = FastAPI()
Expand All @@ -236,9 +243,9 @@ def _clear_fastapi_exception_handlers(self, app: FastAPI) -> None:
self._clear_fastapi_exception_handlers(route.app)

@api.model
@tools.ormcache("root_path")
def get_uid(self, root_path):
record = self.search([("root_path", "=", root_path)])
@tools.ormcache("path")
def get_uid(self, path):
record = self.get_endpoint(path)
if not record:
return None
return record.user_id.id
Expand Down