Skip to content

Commit 9b59ac0

Browse files
committed
Merge PR #574 into 18.0
Signed-off-by lmignon
2 parents 6906d5c + ac614cc commit 9b59ac0

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

fastapi/dependencies.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2022 ACSONE SA/NV
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
33

4-
from typing import TYPE_CHECKING, Annotated
4+
from typing import Annotated
55

66
from odoo.api import Environment
77
from odoo.exceptions import AccessDenied
@@ -13,11 +13,9 @@
1313
from fastapi.security import HTTPBasic, HTTPBasicCredentials
1414

1515
from .context import odoo_env_ctx
16+
from .models.fastapi_endpoint import FastapiEndpoint
1617
from .schemas import Paging
1718

18-
if TYPE_CHECKING:
19-
from .models.fastapi_endpoint import FastapiEndpoint
20-
2119

2220
def company_id() -> int | None:
2321
"""This method may be overriden by the FastAPI app to set the allowed company

fastapi/models/fastapi_endpoint.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from fastapi import APIRouter, Depends, FastAPI
1616

17-
from .. import dependencies
1817
from ..middleware import ASGIMiddleware
1918

2019
_logger = logging.getLogger(__name__)
@@ -310,9 +309,12 @@ def _get_app(self) -> FastAPI:
310309
return app
311310

312311
def _get_app_dependencies_overrides(self) -> dict[Callable, Callable]:
312+
# Import here to avoid circular import while waiting for lazy imports
313+
from ..dependencies import company_id, fastapi_endpoint_id
314+
313315
return {
314-
dependencies.fastapi_endpoint_id: partial(lambda a: a, self.id),
315-
dependencies.company_id: partial(lambda a: a, self.company_id.id),
316+
fastapi_endpoint_id: partial(lambda a: a, self.id),
317+
company_id: partial(lambda a: a, self.company_id.id),
316318
}
317319

318320
def _prepare_fastapi_app_params(self) -> dict[str, Any]:
@@ -337,4 +339,7 @@ def _get_fastapi_app_middlewares(self) -> list[Middleware]:
337339

338340
def _get_fastapi_app_dependencies(self) -> list[Depends]:
339341
"""Return the dependencies to use for the fastapi app."""
340-
return [Depends(dependencies.accept_language)]
342+
# Import here to avoid circular import too
343+
from ..dependencies import accept_language
344+
345+
return [Depends(accept_language)]

0 commit comments

Comments
 (0)