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

[14.0] [FIX] fastapi: Compatibility with latest Odoo #417

Merged
merged 3 commits into from
Mar 11, 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:3c8b420aae65685a897c84203627ccb5386a1465fef40437078f0e9bc997da71
!! source digest: sha256:9d73e697d0dbb3480b1214cd4894b17232e69a627384b9500daefbc392bbd671
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
1 change: 1 addition & 0 deletions fastapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"external_dependencies": {
"python": [
"fastapi",
"pydantic<2",
"python-multipart",
"ujson",
"a2wsgi",
Expand Down
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 @@
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 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
# 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 61 in fastapi/fastapi_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

fastapi/fastapi_dispatcher.py#L61

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

@contextmanager
Expand Down
3 changes: 2 additions & 1 deletion fastapi/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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(),
}

Expand Down
2 changes: 1 addition & 1 deletion fastapi/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,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:3c8b420aae65685a897c84203627ccb5386a1465fef40437078f0e9bc997da71
!! source digest: sha256:9d73e697d0dbb3480b1214cd4894b17232e69a627384b9500daefbc392bbd671
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/14.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-14-0/rest-framework-14-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=14.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