Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16][FIX] fastapi: Compatibility with latest Odoo #416

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion fastapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@
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:

Check warning on line 49 in fastapi/fastapi_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

fastapi/fastapi_dispatcher.py#L49

Added line #L49 was not covered by tests
# 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

Check warning on line 55 in fastapi/fastapi_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

fastapi/fastapi_dispatcher.py#L55

Added line #L55 was not covered by tests
environ = httprequest.environ
environ["wsgi.input"] = httprequest._get_stream_for_parsing()
return environ

@contextmanager
Expand Down
6 changes: 6 additions & 0 deletions fastapi/readme/newsfragments/414.bugfix
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion fastapi/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Odoo FastAPI</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:439e51bdd708113a0ee8a644f2ca42d29c286af1aee25fa6035b743321969c88
!! source digest: sha256:de5a0e0642df22387984fd10d2e54007b88126bacdb22e9e8b637c6187abaeeb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon provides the basis to smoothly integrate the <a class="reference external" href="https://fastapi.tiangolo.com/">FastAPI</a>
Expand Down
Loading