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.0][FIX] Make fastapi compatible with python 3.6 #359

Closed
Closed
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
15 changes: 12 additions & 3 deletions fastapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ that returns a list of partners.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from fastapi import APIRouter
from pydantic import BaseModel
Expand Down Expand Up @@ -306,7 +309,10 @@ odoo models and the database from your route handlers.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from odoo.api import Environment
from odoo.addons.fastapi.dependencies import odoo_env
Expand Down Expand Up @@ -1227,7 +1233,10 @@ you be consistent when writing a route handler for a search route.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated
from pydantic import BaseModel

from odoo.api import Environment
Expand Down
1 change: 1 addition & 0 deletions fastapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"ujson",
"a2wsgi",
"parse-accept-language",
"typing_extensions",
]
},
"development_status": "Beta",
Expand Down
9 changes: 7 additions & 2 deletions fastapi/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Copyright 2022 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
from typing import TYPE_CHECKING, Union

try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from typing import TYPE_CHECKING, Annotated

from odoo.api import Environment
from odoo.exceptions import AccessDenied
Expand Down Expand Up @@ -109,7 +114,7 @@ def fastapi_endpoint(

def accept_language(
accept_language: Annotated[
str | None,
Union[str, None],
Header(
alias="Accept-Language",
description="The Accept-Language header is used to specify the language "
Expand Down
9 changes: 7 additions & 2 deletions fastapi/models/fastapi_endpoint_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Copyright 2022 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
from typing import Annotated, Any, List
from typing import Any, Dict, List

try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from odoo import _, api, fields, models
from odoo.api import Environment
Expand Down Expand Up @@ -71,7 +76,7 @@ def _get_app(self):
] = authenticated_partner_impl_override
return app

def _prepare_fastapi_app_params(self) -> dict[str, Any]:
def _prepare_fastapi_app_params(self) -> Dict[str, Any]:
params = super()._prepare_fastapi_app_params()
if self.app == "demo":
tags_metadata = params.get("openapi_tags", []) or []
Expand Down
15 changes: 12 additions & 3 deletions fastapi/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ that returns a list of partners.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from fastapi import APIRouter
from pydantic import BaseModel
Expand Down Expand Up @@ -232,7 +235,10 @@ odoo models and the database from your route handlers.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from odoo.api import Environment
from odoo.addons.fastapi.dependencies import odoo_env
Expand Down Expand Up @@ -1153,7 +1159,10 @@ you be consistent when writing a route handler for a search route.

.. code-block:: python

from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated
from pydantic import BaseModel

from odoo.api import Environment
Expand Down
5 changes: 4 additions & 1 deletion fastapi/routers/demo_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
The demo router is a router that demonstrates how to use the fastapi
integration with odoo.
"""
from typing import Annotated
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated

from odoo.api import Environment
from odoo.exceptions import AccessError, MissingError, UserError, ValidationError
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pydantic
pyquerystring
python-multipart
typing-extensions
typing_extensions
ujson
Loading