diff --git a/fastapi/README.rst b/fastapi/README.rst index 0b91ed047..2997d96fd 100644 --- a/fastapi/README.rst +++ b/fastapi/README.rst @@ -7,7 +7,7 @@ Odoo FastAPI !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:3c8b420aae65685a897c84203627ccb5386a1465fef40437078f0e9bc997da71 + !! source digest: sha256:9d73e697d0dbb3480b1214cd4894b17232e69a627384b9500daefbc392bbd671 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/fastapi/__manifest__.py b/fastapi/__manifest__.py index 7e9920efa..97d330467 100644 --- a/fastapi/__manifest__.py +++ b/fastapi/__manifest__.py @@ -23,6 +23,7 @@ "external_dependencies": { "python": [ "fastapi", + "pydantic<2", "python-multipart", "ujson", "a2wsgi", diff --git a/fastapi/fastapi_dispatcher.py b/fastapi/fastapi_dispatcher.py index e2ff180e8..a74c44b49 100644 --- a/fastapi/fastapi_dispatcher.py +++ b/fastapi/fastapi_dispatcher.py @@ -48,8 +48,19 @@ def _make_response(self, status_mapping, headers_tuple, content): self.headers = dict(headers_tuple) def _get_environ(self): - environ = self.request.httprequest.environ - environ["wsgi.input"] = self.request.httprequest._get_stream_for_parsing() + try: + # normal case after + # https://github.com/odoo/odoo/commit/cb1d057dcab28cb0b0487244ba99231ee292502e + httprequest = self.request.httprequest._HTTPRequest__wrapped + except AttributeError: + # fallback for older odoo versions + # The try except is the most efficient way to handle this + # as we expect that most of the time the attribute will be there + # and this code will no more be executed if it runs on an up to + # date odoo version. (EAFP: Easier to Ask for Forgiveness than Permission) + httprequest = self.request.httprequest + environ = httprequest.environ + environ["wsgi.input"] = httprequest._get_stream_for_parsing() return environ @contextmanager diff --git a/fastapi/models/fastapi_endpoint.py b/fastapi/models/fastapi_endpoint.py index ed255b9a7..3c2cf3632 100644 --- a/fastapi/models/fastapi_endpoint.py +++ b/fastapi/models/fastapi_endpoint.py @@ -214,6 +214,8 @@ def _get_app(self) -> FastAPI: app = FastAPI(**self._prepare_fastapi_app_params()) for router in self._get_fastapi_routers(): app.include_router(router=router) + for middleware, options in self._get_fastapi_app_middlewares(): + app.add_middleware(middleware, **options) app.dependency_overrides[dependencies.fastapi_endpoint_id] = partial( lambda a: a, self.id ) @@ -258,7 +260,6 @@ def _prepare_fastapi_app_params(self) -> Dict[str, Any]: return { "title": self.name, "description": self.description, - "middleware": self._get_fastapi_app_middlewares(), "dependencies": self._get_fastapi_app_dependencies(), } diff --git a/fastapi/static/description/index.html b/fastapi/static/description/index.html index 8d9391d42..ab33ce9a6 100644 --- a/fastapi/static/description/index.html +++ b/fastapi/static/description/index.html @@ -367,7 +367,7 @@

Odoo FastAPI

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:3c8b420aae65685a897c84203627ccb5386a1465fef40437078f0e9bc997da71 +!! source digest: sha256:9d73e697d0dbb3480b1214cd4894b17232e69a627384b9500daefbc392bbd671 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: LGPL-3 OCA/rest-framework Translate me on Weblate Try me on Runboat

This addon provides the basis to smoothly integrate the FastAPI