Skip to content

Commit

Permalink
[FIX] fastapi: Compatibility with latest Odoo
Browse files Browse the repository at this point in the history
From odoo/odoo@cb1d057, 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
  • Loading branch information
lmignon authored and renda-dev committed Feb 27, 2024
1 parent a2564dc commit d87a299
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d87a299

Please sign in to comment.