Skip to content

Commit 018f44d

Browse files
committed
[IMP]fastapi: obtain endpoint via common method
1 parent e24654c commit 018f44d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

fastapi/fastapi_dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def dispatch(self, endpoint, args):
2727
# don't parse the httprequest let starlette parse the stream
2828
self.request.params = {} # dict(self.request.get_http_params(), **args)
2929
environ = self._get_environ()
30-
root_path = "/" + environ["PATH_INFO"].split("/")[1]
30+
root_path = environ["PATH_INFO"]
3131
# TODO store the env into contextvar to be used by the odoo_env
3232
# depends method
3333
with fastapi_app_pool.get_app(env=request.env, root_path=root_path) as app:

fastapi/models/fastapi_endpoint.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,15 @@ def _reset_app_cache_marker(self):
210210
to all the running instances.
211211
"""
212212

213+
@api.model
214+
def get_endpoint(self, root_path):
215+
root_path = "/" + root_path.split("/")[1]
216+
endpoint = self.search([("root_path", "=", root_path)])[:1] or False
217+
return endpoint
218+
213219
@api.model
214220
def get_app(self, root_path):
215-
record = self.search([("root_path", "=", root_path)])
221+
record = self.get_endpoint(root_path)
216222
if not record:
217223
return None
218224
app = FastAPI()
@@ -238,7 +244,7 @@ def _clear_fastapi_exception_handlers(self, app: FastAPI) -> None:
238244
@api.model
239245
@tools.ormcache("root_path")
240246
def get_uid(self, root_path):
241-
record = self.search([("root_path", "=", root_path)])
247+
record = self.get_endpoint(root_path)
242248
if not record:
243249
return None
244250
return record.user_id.id

0 commit comments

Comments
 (0)