From 8c95a74c790c188f5dc0a2dcf9996da11007c6ae Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 20 Feb 2024 10:27:27 +0100 Subject: [PATCH] [FIX] fastapi: Compatibility with latest Odoo From https://github.com/odoo/odoo/commit/cb1d057dcab28cb0b0487244ba99231ee292502e, the orignal werkzeug request is wrapped in a dedicated class to keep under control the attributes developers use. This change add code to make the fastapi addon working with version including this last change and prior version refs #414 --- fastapi/README.rst | 2 +- fastapi/fastapi_dispatcher.py | 15 +++++++++++++-- fastapi/readme/newsfragments/414.bugfix | 6 ++++++ fastapi/static/description/index.html | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 fastapi/readme/newsfragments/414.bugfix diff --git a/fastapi/README.rst b/fastapi/README.rst index 438bf8cd..c287f07d 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:439e51bdd708113a0ee8a644f2ca42d29c286af1aee25fa6035b743321969c88 + !! source digest: sha256:de5a0e0642df22387984fd10d2e54007b88126bacdb22e9e8b637c6187abaeeb !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/fastapi/fastapi_dispatcher.py b/fastapi/fastapi_dispatcher.py index 904deeff..02738b9b 100644 --- a/fastapi/fastapi_dispatcher.py +++ b/fastapi/fastapi_dispatcher.py @@ -42,8 +42,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/readme/newsfragments/414.bugfix b/fastapi/readme/newsfragments/414.bugfix new file mode 100644 index 00000000..995a1fc1 --- /dev/null +++ b/fastapi/readme/newsfragments/414.bugfix @@ -0,0 +1,6 @@ +Fix compatibility issues with the latest Odoo version + +From https://github.com/odoo/odoo/commit/cb1d057dcab28cb0b0487244ba99231ee292502e +the original werkzeug HTTPRequest class has been wrapped in a new class to keep +under control the attributes developers use. This changes take care of this +new implementation but also keep compatibility with the old ones. diff --git a/fastapi/static/description/index.html b/fastapi/static/description/index.html index e7e699db..6d439c4d 100644 --- a/fastapi/static/description/index.html +++ b/fastapi/static/description/index.html @@ -1,3 +1,4 @@ + @@ -366,7 +367,7 @@

Odoo FastAPI

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:439e51bdd708113a0ee8a644f2ca42d29c286af1aee25fa6035b743321969c88 +!! source digest: sha256:de5a0e0642df22387984fd10d2e54007b88126bacdb22e9e8b637c6187abaeeb !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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